1

I coded an MIP in CPLEX with C#. I declared variables and constraints and added the objective but I cannot get the correct answer. Is there a way to print the model into a string variable or something like in order to check whether I coded correctly the model I had in mind?

1 Answer 1

4

You could try exporting it in CPLEX LP format, that is human readable.

I use neither CPLEX nor .NET, but according this website the function you are looking for is:

LOG CPLEX .NET Reference Manual Cplex.ExportModel Method

Writes the active model to the file specified by filename.

public virtual void ExportModel( String name );

Parameters

name
The name of the file to which the model is written. The extension of the filename determines the format in which to write the model file.

Remarks

The file format is determined by the extension of the filename. The following extensions are recognized on most platforms:

.sav
.mps
.Lp
[...]

Hope this helps.

3
  • 1
    That is correct. You can also look at the C# examples provided with CPLEX, such as LPex1.cs which does this: May 4, 2014 at 9:17
  • Thank you. I found the ExportModel method from the dcoumentation as well. I looked around a little more and I found out that the ToString methods dumps all the constraints into a string variable that's what I was looking for so thank you. May 4, 2014 at 22:07
  • @user3599645 I am glad if you find the answer helpful. Here at Stackoverflow we don't say thank you, we accept or upvote the answer if we find it helpful. See also How does accepting an answer work? In any case, good luck!
    – Ali
    May 4, 2014 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.