Initializing help system before first use

Embedding Mosel models into a host application

The following simple Java program can be used to run a Mosel model that is provided in the form of a BIM file (for simplicity's sake we are leaving out any kind of error handling):

import com.dashoptimization.*;

public class folio
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel model;

  mosel = new XPRM();                         // Initialize Mosel
  model = mosel.loadModel("foliodata.bim");   // Load compiled model
  model.run();                                // Run the model

  System.out.println("Model execution returned: " + model.getResult());
 }
}

This Java program may be run on all systems for which Mosel is available. Under Windows use these commands to compile and run the program:

javac -classpath .:%XPRESSDIR%\lib\xprm.jar folio.java
java -classpath .:%XPRESSDIR%\lib\xprm.jar folio

To compile under Linux or Solaris use:

javac -cp .:${XPRESSDIR}/lib/xprm.jar folio.java

If we also wish to create the BIM file from the Java application, we may compile, load, and run the Mosel model foliodata.mos directly from the Java program, for instance as shown in the following code fragment. The compilation functionality is equally contained in the JAR file xprm.jar so that we can use the same compilation command as before.

import com.dashoptimization.*;

public class folio
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel model;

  mosel = new XPRM();                         // Initialize Mosel
  mosel.compile("foliodata.mos");             // Compile the model
  model = mosel.loadModel("foliodata.bim");   // Load compiled model
  model.run();                                // Run the model

  System.out.println("Model execution returned: " + model.getResult());
 }
}

Parameters

In Chapter 4 we have shown how to modify parameter settings with Workbench or when running the Mosel standalone version (for instance in batch files or scripts). The model parameters may also be reset when a Mosel model or BIM file is embedded in an application, making it possible to solve many different problem instances without having to change the model source.

In this example we modify the name of the result file and the settings for two numerical parameters of our model foliodata.mos. All other model parameters will take the default values specified at their definition in the model.

import com.dashoptimization.*;

public class folioparam
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel model;

  mosel = new XPRM();                        // Initialize Mosel
  mosel.compile("foliodata.mos");            // Compile the model
  model = mosel.loadModel("foliodata.bim");  // Load compiled model
                                             // Set the run-time parameters
  model.execParams = "OUTFILE=result2.dat,MAXRISK=0.4,MAXVAL=0.25";
  model.run();                               // Run the model

  System.out.println("`foliodata' returned: " + model.getResult());
 }
}

Retrieving solution information

After running a model, it is possible to retrieve information about the model objects and the solution of the (last) optimization run. The following example shows how to test the problem status and retrieve the objective function value.

import com.dashoptimization.*;

public class folioobj
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel model;

  mosel = new XPRM();                        // Initialize Mosel
  mosel.compile("foliodata.mos");            // Compile the model
  model = mosel.loadModel("foliodata.bim");  // Load compiled model
  model.run();                               // Run the model

  // Test whether a solution is found and print the objective value
  if(model.getProblemStatus()==XPRMModel.PB_OPTIMAL)
    System.out.println("Objective value: " + model.getObjectiveValue());
 }
}

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.