/********************************************************
Xpress-BCL Java Example Problems
================================
file xbgoalobj.java
```````````````````
Archimedian and pre-emptive goal programming
using objective functions.
(c) 2008 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
{
XPRB bcl;
XPRBvar x,y;
XPRBexpr[] goal;
XPRBexpr wobj;
XPRBctr[] goalCtr;
XPRBctr aCtr;
double[] Target;
XPRBprob prob;
int i,g;
bcl = new XPRB(); /* Initialize BCL */
prob = bcl.newProb("Goal"); /* Create a new problem */
XPRS.init(); /* Initialize Xpress-Optimizer */
Target = new double[NGOALS];
goalCtr = new XPRBctr[NGOALS];
goal = new XPRBexpr[NGOALS];
wobj = new XPRBexpr();
/* Adding the variables */
x = prob.newVar("x",XPRB.PL);
y = prob.newVar("y",XPRB.PL);
/* Adding a constraint */
aCtr = prob.newCtr("Limit", x.mul(42) .add(y.mul(13)) .lEql(100) );
/* Goals */
goal[0] = x.mul(5) .add(y.mul(2)) .add(-20);
goal[1] = x.mul(-3) .add(y.mul(15)) .add(-48);
goal[2] = x.mul(1.5) .add(y.mul(21)) .add(-3.8);
for(g=0;g= ":" <= ") + Target[g]);
if(g==NGOALS-1)
System.out.println(" " + prob.getObjVal());
else
System.out.println(" " + (goalCtr[g].getAct() - goalCtr[g].getRHS()
+ Target[g]));
}
}
}
|