Topic
• 7 replies
• Latest Post - ‏2013-01-02T16:15:17Z by SystemAdmin
7929 Posts

# Pinned topic Solve a matrix equation with ILP?

‏2012-12-29T12:03:55Z |
Hello, everyone! I would like to solve with CPLEX a matrix equation of the form:

n1 = n0 + C*x.

n1 and n0 as well as C (three matrices) are given, x must be calculated (integer solution).

For example see the attached file. The last matrix with 1 column and 3 rows is not given and must be found.

I'm new to CPLEX, any help is very much appreciated!

#### Attachments

Updated on 2013-01-02T16:15:17Z at 2013-01-02T16:15:17Z by SystemAdmin
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2012-12-29T17:00:03Z
Hello,

You can do something like this:

Minimize
Obj: c1 + c2 + c3
Subject To
R1: -2c1 + c2 + c3 = 1
R2: c1 - c2 = 0
R3: c1 - c3 = -1
R4: -2c2 + 2c3 = 2
General
c1 c2 c3
End

The solution to this is 0, 0, 1.

You could either use C callable library or C++/Java Concert or some other means that you are comfortable with, to load your matrix into CPLEX data structures. Once you do that, then you can use any of the CPLEX optimizers to solve the problem. In case of many solutions to your problem, the above would find the minimum of the sum. You could try other functions too.

Regards,
Vivek.
Updated on 2014-03-24T22:43:34Z at 2014-03-24T22:43:34Z by iron-man
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2012-12-29T18:06:45Z
Hello,

You can do something like this:

<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">Minimize Obj: c1 + c2 + c3 Subject To R1: -2c1 + c2 + c3 = 1 R2: c1 - c2 = 0 R3: c1 - c3 = -1 R4: -2c2 + 2c3 = 2 General c1 c2 c3 End </pre>

The solution to this is 0, 0, 1.

You could either use C callable library or C++/Java Concert or some other means that you are comfortable with, to load your matrix into CPLEX data structures. Once you do that, then you can use any of the CPLEX optimizers to solve the problem. In case of many solutions to your problem, the above would find the minimum of the sum. You could try other functions too.

Regards,
Vivek.
Hello VivekPeriaraj,

thank you very much! I was looking for it, it is great!

I have two questions:

1) What function can I use to store/enumerate all possible solutions (if there are more then 1 solution).
2) I am going to use Java to load the matrix into CPLEX and then get the results back into the program. I am familiar with Java, however I am new to CPLEX. Could you give me some code examples, how to load data (the above matrix) into CPLEX and how to get the results back?

Thank you!
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2012-12-29T19:01:15Z
Hello VivekPeriaraj,

thank you very much! I was looking for it, it is great!

I have two questions:

1) What function can I use to store/enumerate all possible solutions (if there are more then 1 solution).
2) I am going to use Java to load the matrix into CPLEX and then get the results back into the program. I am familiar with Java, however I am new to CPLEX. Could you give me some code examples, how to load data (the above matrix) into CPLEX and how to get the results back?

Thank you!
Hi Mark,

1) You could use the 'solution pool' feature of CPLEX to do that. You can find more abt it here:

http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r3/index.jsp?topic=%2Filog.odms.cplex.help%2FContent%2FOptimization%2FDocumentation%2FOptimization_Studio%2F_pubskel%2Fps_usrmancplex1900.html

2) You can find many examples in the CPLEX install directory. In my install, I find it here -> cplex/examples/src/java

Regards,
Vivek.
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2012-12-29T21:11:02Z
Hi Mark,

1) You could use the 'solution pool' feature of CPLEX to do that. You can find more abt it here:

http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r3/index.jsp?topic=%2Filog.odms.cplex.help%2FContent%2FOptimization%2FDocumentation%2FOptimization_Studio%2F_pubskel%2Fps_usrmancplex1900.html

2) You can find many examples in the CPLEX install directory. In my install, I find it here -> cplex/examples/src/java

Regards,
Vivek.
Thank you VivekPeriaraj,

I will try to use that feature. Then I will get familiar with the available examples in the CPLEX install directory and try to implement my program.

Thanks again.
Best regards.
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2012-12-30T15:06:15Z
Thank you VivekPeriaraj,

I will try to use that feature. Then I will get familiar with the available examples in the CPLEX install directory and try to implement my program.

Thanks again.
Best regards.
Hello, One point to note is that the enumerate from the solution pool would only populate feasible solutions that the optimizer find while it parses through the tree and not all of them like you want.

Good luck!

Vivek.
7929 Posts

#### Re: Solve a matrix equation with ILP?

‏2013-01-02T07:24:38Z
Hello, One point to note is that the enumerate from the solution pool would only populate feasible solutions that the optimizer find while it parses through the tree and not all of them like you want.

Good luck!

Vivek.
If you set the solution pool intensity while populating the pool then CPLEX should enumerate all feasible solutions.