GoalObj - Archimedian and pre-emptive goal programming using objective functions
|
|
|
| Type: | Goal Programming |
| Rating: | 3 (intermediate) |
| 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. |
| File(s): | xbgoalobj.cs, xbgoalobj.csproj |
|
|
|
| xbgoalobj.cs |
/********************************************************
Xpress-BCL C# Example Problems
==============================
file xbgoalobj.cs
`````````````````
Archimedian and pre-emptive goal programming
using objective functions.
(c) 2008 Fair Isaac Corporation
authors: S.Heipcke, D.Brett.
********************************************************/
using System;
using System.Text;
using System.IO;
using Optimizer;
using BCL;
namespace Examples
{
public class TestAdvGoalObj
{
const int NGOALS = 3;
// **** Data ****
string[] Type = {"perc", "abs", "perc"};
string[] Sense = {"max", "min", "max"};
double[] Weight = {100, 1, 0.1};
double[] Deviation = {10, 4, 20};
public void modelgo()
{
XPRBvar x,y;
XPRBctr[] goalCtr = new XPRBctr[NGOALS];
XPRBctr aCtr;
double[] Target = new double[NGOALS];
XPRBexpr[] goal = new XPRBexpr[NGOALS];
XPRBexpr wobj;
XPRBprob prob;
XPRSprob xprsp;
int i,g;
prob = new XPRBprob("Goal");
// Adding the variables
x = prob.newVar("x", BCLconstant.XPRB_PL);
y = prob.newVar("y", BCLconstant.XPRB_PL);
// Adding a constraint
aCtr = prob.newCtr("Limit", 42*x + 13*y <= 100);
// Goals
goal[0] = 5*x + 2*y - 20;
goal[1] = -3*x + 15*y - 48;
goal[2] = 1.5*x + 21*y - 3.8;
for(g=0;g<NGOALS;g++)
goalCtr[g] = prob.newCtr("Goal" + (g+1), goal[g]);
// **** Archimedian GP ****
System.Console.WriteLine("Archimedian:");
wobj = new XPRBexpr(0);
for(g=0;g<NGOALS;g++)
{
if (Sense[g] == "max")
wobj -= (Weight[g]*goal[g]);
else
wobj += (Weight[g]*goal[g]);
}
prob.setObj(prob.newCtr(wobj));
xprsp = prob.getXPRSprob();
xprsp.OutputLog = 0;
prob.setSense(BCLconstant.XPRB_MINIM);
prob.lpOptimize();
// Solution printout
System.Console.WriteLine(" Solution: x: " + x.getSol() + ", y: " +
y.getSol());
System.Console.WriteLine(" Goal Target Value");
for(g=0;g<NGOALS;g++)
System.Console.WriteLine(" " + (g+1) + " " + Sense[g] +
" " + (goalCtr[g].getAct() - goalCtr[g].getRHS()));
// **** Prememptive GP ****
System.Console.WriteLine("Prememptive:");
i=-1;
while (i<NGOALS-1)
{
i+=1;
if (Sense[i] == "max")
{
prob.setObj(prob.newCtr("GoalO" + (i + 1), goal[i]));
prob.setSense(BCLconstant.XPRB_MAXIM);
prob.lpOptimize();
if (prob.getLPStat() != BCLconstant.XPRB_LP_OPTIMAL)
{
System.Console.WriteLine("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];
if (i<NGOALS-1) goalCtr[i] -= Target[i];
goalCtr[i].setType(BCLconstant.XPRB_G);
}
}
else
{
prob.setObj(prob.newCtr("Objective" + i, goal[i]));
prob.setSense(BCLconstant.XPRB_MINIM);
prob.lpOptimize();
if (prob.getLPStat() != BCLconstant.XPRB_LP_OPTIMAL)
{
System.Console.WriteLine("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];
if (i<NGOALS-1) goalCtr[i] -= Target[i];
goalCtr[i].setType(BCLconstant.XPRB_L);
}
}
System.Console.WriteLine("Solution(" + (i+1) + "): x: " +
x.getSol() + ", y: " + y.getSol());
}
// Solution printout
System.Console.WriteLine(" Goal Target Value");
for(g=0;g<=i;g++)
{
System.Console.Write(" " + (g+1) + " " +
(goalCtr[g].getType()==BCLconstant.XPRB_G?" >= ":" <= ")+
Target[g]);
if(g==NGOALS-1)
System.Console.WriteLine(" " + prob.getObjVal());
else
System.Console.WriteLine(" " + (goalCtr[g].getAct() -
goalCtr[g].getRHS() + Target[g]));
}
}
public static void Main()
{
XPRB.init();
TestAdvGoalObj TestInstance = new TestAdvGoalObj();
if (XPRB.init() != 0) return;
TestInstance.modelgo();
XPRB.finish();
return;
}
}
} |
| xbgoalobj.csproj |
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FICO.Xpress.XPRBdn" Version="4.10.6" /> <!-- Version 4.10.6 or later -->
</ItemGroup>
</Project> |
© 2001-2022 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.
