FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Runprime - Remote model execution

Description
  • runprimedistr.c, runprimedistr.java, runprimedistr.mos: Running a model on a remote Mosel instance (requires prime.mos)
  • runprimeiodistr.c, runprimeiodistr.java: Running a model on a remote Mosel instance and retrieving output data: data saved to file or in memory on the remote machine (requires primeio.mos)
  • runprimeiodistr2.c, runprimeiodistr2.java: Running a model on a remote Mosel instance and retrieving output data: data saved in memory on the local machine. Implementation of a file manager for data exchange in memory (requires primeio.mos)
  • runprimeiodistr3.c, runprimeiodistr3.java: Running a model on a remote Mosel instance and retrieving output data: data saved to a file on the local machine (requires primeio.mos)
  • runprimeiodistr.mos: mmjobs implementation. Running a model on a remote Mosel instance and retrieving output data (requires primeio.mos)
Further explanation of this example: 'Mosel User Guide', Chapters XPRD C and XPRD Java


Source Files





runprimedistr.java

/******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file runprimedistr.java 
   ```````````````````````
   Distributed computing: 
   Running a model on a remote Mosel instance.
  
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Feb 2012
*******************************************************/

import com.dashoptimization.*;
import java.lang.*;
import java.io.*;

public class runprimedistr
{
 public static void main(String[] args) throws Exception
 {
  XPRD xprd=new XPRD();
  XPRDMosel moselInst;
  XPRDModel modPrime;
  XPRDEvent event;

  moselInst=xprd.connect("");    // Open connection to remote nodes
                                 // "" means the node running this program
    
                                 // Compile the model file on remote instance
  moselInst.compile("", "rmt:prime.mos", "rmt:prime.bim");
  
	                         // Load the bim file into remote instance
  modPrime=moselInst.loadModel("rmt:prime.bim"); 

  modPrime.execParams = "LIMIT=50000";
  modPrime.run();                // Start execution and
  xprd.waitForEvent(2);          // wait 2 seconds for an event

  if (xprd.isQueueEmpty())       // No event has been sent...
  {
   System.out.println("Model too slow: stopping it!");
   modPrime.stop();              // ... stop the model, then wait
   xprd.waitForEvent();
  }
                                 // An event is available: model finished
  event=xprd.getNextEvent();
  System.out.println("Event value: " + event.value +
                     " sent by model " + event.sender.getNumber());
  System.out.println("Exit status: " + modPrime.getExecStatus());
  System.out.println("Exit code  : " + modPrime.getResult());

  moselInst.unloadModel(modPrime);  // Unload the submodel
  moselInst.disconnect();           // Terminate the connection

  new File("prime.bim").delete();   // Clean up temporary files
 }
} 


Back to examples browserPrevious exampleNext example