3

I have a question concerning the communication of two Java programs, one embeds the other.

The embedded one is a CPLEX linear program (Java SE + CPLEX libs) which calculates resources and the other root application is a simulation software (AnyLogic). Now the idea is that the simulation should use the resources calculated by the linear program.

I now want the simulation to call the linear program, which then calculates the resources and hands them back as an array or object, then the simulation continues.

Simulation (AnyLogic) ----> Linear Program (CPLEX)
             <--------(VALUES?)--------|

My problem is the "hand over", return values (args) seam not enough. How can I do this?

At the moment I use a text file which stores the values. I read about RMI and sockets but don't know if this is such a good idea.

Any help is appreciated! Thank you.

Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52
lony
  • 6,733
  • 11
  • 60
  • 92
  • What do the docs of the simulation program say? Do they specify any way of calling another program or adding your own classes to the simulation? – markspace Jul 27 '14 at 18:25
  • Nothing special, only the other way around. Running AnyLogic inside another application. – lony Jul 28 '14 at 06:52
  • From the text so far (including Dylan's answer and comments), I still don't understand the context. What does "return values (args) seam not enough" mean? If your linear program (LP) is Java, is the problem that (a) there is no API for it to get it to calculate without running it as a command-line app? (b) the API doesn't give you the responses in the the array/object form you want? (c) something else? Some sample Java would be useful if you tried to code something and it didn't work. – Stuart Rossiter Oct 28 '14 at 22:20

1 Answers1

1

One way of doing it is launching your CPLEX program using a Java Process. The first answer to this question details how to get feedback from a launched Process (and how to launch it). Specifically, it shows how to launch a Process that prints its output that is subsequently read by the launching program. I imagine that your CPLEX program could print out any relevant results, which your AnyLogic simulation could then take in via the described mechanism.

Community
  • 1
  • 1
Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52
  • This is working but isn't this not a bit to "hardcore".Because both programs are Java is there nothing "better" to serialize data. This way I also could use my CSV ex/import. But really interesting idea thanks, this helps me with another problem :) – lony Oct 20 '14 at 20:52
  • As far as I know, this is the only way to do it. I agree, though: it does seem cumbersome. – Dylan Knowles Oct 20 '14 at 21:44