2
$\begingroup$

I am a beginner in CPLEX. I have a model with about 1 million constants and 800k rows and 1.6 million columns. I implemented in both GAMS and CPLEX (C# as the platform). The final solution for both is the same but the computational time for building the model (before solve) in CPLEX is much more than GAMS( about 2 hours vs 30 seconds). I have no idea why it happens and how it can be solved. A sample as coding one of my constraints is as follows in C#.

for (int ss = 1; ss <= s; ss++) {
    for (int tt = 1; tt <= t; tt++) {
        if (ss != source && ss != sink) {
            string c1 = "const01(" + (ss) + "," + (tt).ToString() + "): ";
            ILinearNumExpr eq01 = MODEL.LinearNumExpr();
                                    
             for (int nn = 1; nn <= n; nn++) {
                 if (nbels[nn, ss] == 1 && pdw[nn, ss] > 0) {
                     eq01.AddTerm(1 / pdw[nn, ss], x[nn][ss][tt]);
                 }
             }
             eq01.AddTerm(1, sVar01[ss][tt]);
             MODEL.AddEq(eq01, cap[ss, tt], c1);
        }
    }
}

I would appreciate if you help me to solve this problem.

$\endgroup$
9
  • $\begingroup$ You need to fix the formatting of your question to make the C# code clearer. $\endgroup$
    – prubin
    Oct 17 at 16:02
  • $\begingroup$ @pouria, welcome to OR.SE. I am not sure about C#, but GAMS has a fast pre-processing step rather than. Other optimization python-based software. $\endgroup$
    – A.Omidi
    Oct 17 at 18:20
  • $\begingroup$ I've done that. If you have a CPLEX license you might also be able to ask them about their C++ interface. The code itself doesn't give me enough information to say anything. But it is likely that you hit some $O(n^2)$ behavior. What version of cplex are you using? $\endgroup$ Oct 17 at 18:21
  • 2
    $\begingroup$ I don't know much about C# but just a few observations: 1) Do you need to define a string c1 name for the constraint? I think you can define your constraints without names. 2) Cant you use batch definition for your constraints? For example, rather than using AddTerm, is it possible to use AddTerms and get rid of a loop? 3) can you define a combo index first for [ss][tt], define your variables and coefficients using that combo index, and consequently, remove one more loop? $\endgroup$
    – EhsanK
    Oct 17 at 23:42
  • $\begingroup$ Thank you for your reply @A.Omidi $\endgroup$ Oct 21 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.