FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

GoalObj - Archimedian and pre-emptive goal programming using objective functions

Description
A small linear problem with multiple objectives is solved by Archimedian and pre-emptive goal programming. The example uses functions to access information about constraints and shows how to solve a problem repeatedly with a modified objective function.

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

xbgoalobj.java

/********************************************************
Xpress-BCL Java Example Problems
================================

file xbgoalobj.java

Archimedian and pre-emptive goal programming
using objective functions.

(c) 2008-2023 Fair Isaac Corporation
author: S.Heipcke, 2005, rev. Mar. 2011
********************************************************/

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

public class xbgoalobj {
static final int NGOALS = 3;

/**** Data ****/
static final String[] Type = {"perc", "abs", "perc"};
static final String[] Sense = {"max", "min", "max"};
static final double[] Weight = {100, 1, 0.1};
static final double[] Deviation = {10, 4, 20};

public static void main(String[] args) throws XPRSprobException, XPRSexception {
XPRBvar x,y;
XPRBexpr[] goal;
XPRBexpr wobj;
XPRBctr[] goalCtr;
XPRBctr aCtr;
double[] Target;
int i,g;

try (XPRBprob prob = new XPRBprob("Goal"); /* Initialize BCL and create a new problem */
XPRS xprs = new XPRS()) {             /* Initialize Xpress-Optimizer */

Target = new double[NGOALS];
goalCtr = new XPRBctr[NGOALS];
goal = new XPRBexpr[NGOALS];
wobj = new XPRBexpr();

x = prob.newVar("x",XPRB.PL);
y = prob.newVar("y",XPRB.PL);

aCtr = prob.newCtr("Limit", x.mul(42) .add(y.mul(13)) .lEql(100) );

/* Goals */
for(g=0;g<NGOALS;g++)
goalCtr[g] = prob.newCtr("Goal"+(g+1), goal[g]);

/**** Archimedian GP ****/
System.out.println("Archimedian:");
for(g=0;g<NGOALS;g++) {
if (Sense[g]=="max")
else
}
prob.setObj(wobj);
prob.getXPRSprob().setIntControl(XPRS.OUTPUTLOG, 0);
prob.lpOptimize("");

/* Solution printout */
System.out.println(" Solution: x: " + x.getSol() + ", y: " + y.getSol());
System.out.println(" Goal   Target     Value");
for(g=0;g<NGOALS;g++)
System.out.println("  " + (g+1) + "       " + Sense[g] + "      " +
(goalCtr[g].getAct() - goalCtr[g].getRHS()));

/**** Prememptive GP ****/
System.out.println("Prememptive:");
i=-1;
while (i<NGOALS-1) {
i+=1;
if (Sense[i]=="max") {
prob.setObj(goal[i]);
prob.setSense(XPRB.MAXIM);
prob.lpOptimize("");
if (prob.getLPStat() != XPRB.LP_OPTIMAL) {
System.out.println("Cannot satisfy goal " + (i+1));
break;
}
else {
Target[i]=prob.getObjVal();
if (Type[i]=="perc")
Target[i]-= Math.abs(Target[i])*Deviation[i]/100;
else
Target[i]-= Deviation[i];
goalCtr[i].setType(XPRB.G);
}
}
else {
prob.setObj(goal[i]);
prob.setSense(XPRB.MINIM);
prob.lpOptimize("");
if (prob.getLPStat() != XPRB.LP_OPTIMAL) {
System.out.println("Cannot satisfy goal " + i);
break;
}
else {
Target[i]=prob.getObjVal();
if (Type[i]=="perc")
Target[i]+= Math.abs(Target[i])*Deviation[i]/100;
else
Target[i]+= Deviation[i];
goalCtr[i].setType(XPRB.L);
}
}
System.out.println("Solution(" + (i+1) + "):  x: " + x.getSol() +
", y: " + y.getSol());
}

/* Solution printout */
System.out.println(" Goal        Target                Value");
for(g=0;g<=i;g++) {
System.out.print("  " + (g+1) + "    " +
(goalCtr[g].getType()==XPRB.G?" >=  ":" <=  ") + Target[g]);
if(g==NGOALS-1)
System.out.println("   " + prob.getObjVal());
else
System.out.println("   " + (goalCtr[g].getAct() - goalCtr[g].getRHS()
+ Target[g]));
}
}
}
}

`