Note how this C++ code uses the Problem, Model,
Solver, Variable and Function objects. When you create an
optimization problem, it automatically has one vector of decision
variables (VarDecision property), one vector of constraints (FcnConstraint
property), and a single-element vector of objectives (FcnObjective
property).
CProblem prob(Solver_Type_Maximize, nvars, ncons);
prob.Model.AllLinear[Function_Type_Objective] =
CDoubleMatrix(Array_Order_ByCol, 1, nvars, objcoeff);
prob.Model.AllLinear[Function_Type_Constraint] =
CDoubleMatrix (Array_Order_ByCol, ncons, nvars, concoeff);
prob.FcnConstraint.UpperBound = rhsvalue;
prob.VarDecision.NonNegative();
prob.VarDecision.IntegerType[0] =
prob.VarDecision.IntegerType[1] = Integer_Type_Integer;
prob.Solver.Optimize();
_Optimize_Status status = prob.Solver.OptimizeStatus;
double x1 =
prob.VarDecision.FinalValue[0];
double x2 =
prob.VarDecision.FinalValue[1];
Note how this C# code excerpt is very similar to
the C++ excerpt above.
Problem prob = new Problem(Solver_Type.Maximize, nvars,
ncons);
prob.Model.AllLinear[Function_Type.Objective] =
new DoubleMatrix(Array_Order.ByCol, 1, nvars, objcoeff);
prob.Model.AllLinear[Function_Type.Constraint] =
new DoubleMatrix(Array_Order.ByCol, ncons, nvars, concoeff);
prob.FcnConstraint.UpperBound.Array = rhsvalue;
prob.VarDecision.NonNegative();
prob.VarDecision.IntegerType[0] = Integer_Type.Integer;
prob.VarDecision.IntegerType[1] = Integer_Type.Integer;
prob.Solver.Optimize();
Optimize_Status status = prob.Solver.OptimizeStatus;
double x1 =
prob.VarDecision.FinalValue[0];
double x2 =
prob.VarDecision.FinalValue[1];
Dim prob As New SolverPlatform.Problem
prob.Solver.SolverType = Solver_Type_Maximize
prob.VarDecision.Size = nvars
prob.FcnConstraint.Size = ncons
Dim objcoeff As New DoubleMatrix
With objcoeff...
prob.Model.AllLinear(Function_Type_Objective, Variable_Type_Decision) = objcoeff
Dim concoeff As New DoubleMatrix
With concoeff...
prob.Model.AllLinear(Function_Type_Constraint,
Variable_Type_Decision) = concoeff
prob.FcnConstraint.UpperBound.Array = rhsvalue
prob.VarDecision.NonNegative
prob.VarDecision.IntegerType(0) = Integer_Type_Integer
prob.VarDecision.IntegerType(1) = Integer_Type_Integer
prob.Solver.Optimize
Dim status As Optimize_Status
status = prob.Solver.OptimizeStatus
Dim varvalue() As Double
varvalue = prob.VarDecision.FinalValue.Array
Note how this VB.NET code excerpt is nearly
identical to the Visual Basic excerpt above.
Dim prob As New SolverPlatform.Problem
prob.Solver.SolverType = Solver_Type_Maximize
prob.VarDecision.Size = nvars
prob.FcnConstraint.Size = ncons
Dim objcoeff As New DoubleMatrix
With objcoeff...
prob.Model.AllLinear(Function_Type_Objective, Variable_Type_Decision) = objcoeff
Dim concoeff As New DoubleMatrix
With concoeff...
prob.Model.AllLinear(Function_Type_Constraint,
Variable_Type_Decision) = concoeff
prob.FcnConstraint.UpperBound.Array = rhsvalue
prob.VarDecision.NonNegative
prob.VarDecision.IntegerType(0) = Integer_Type_Integer
prob.VarDecision.IntegerType(1) = Integer_Type_Integer
prob.Solver.Optimize
Dim status As Optimize_Status
status = prob.Solver.OptimizeStatus
Dim varvalue() As Double
varvalue = prob.VarDecision.FinalValue.Array
The Java language does not have properties, but
the code excerpt below is still quite similar to the C# and C++ code
excerpts above.
prob = new Problem(Solver_Type.Maximize, nvars, ncons);
prob.Model().AllLinear(Function_Type.Objective,
new DoubleMatrix(Array_Order.ByCol, 1,
nvars, objcoeff));
prob.Model().AllLinear(Function_Type.Constraint,
new
DoubleMatrix(Array_Order.ByCol, ncons, nvars, concoeff));
prob.FcnConstraint().UpperBound (rhsvalue);
prob.VarDecision().NonNegative();
prob.VarDecision().IntegerType( new int [] { Integer_Type.Integer, Integer_Type.Integer
} );
prob.Solver().Optimize();
int nOptStatus =
prob.Solver().OptimizeStatus();
double [] varvalue =
prob.VarDecision().FinalValue();
This code excerpt using the SDK's object-oriented
API in MATLAB closely resembles the C++ and C# code excerpts
above. You can also use the SDK's procedural API in MATLAB,
yielding code that is similar to the C language excerpt below.
prob = Problem('Maximize', nvars, ncons);
prob.Model.AllLinear('Objective') = objcoeff;
prob.Model.AllLinear('Constraint') = concoeff;
prob.FcnConstraint.UpperBound = rhsvalue;
NonNegative(prob.VarDecision);
prob.VarDecision.IntegerType(0) = 'Integer';
prob.VarDecision.IntegerType(1) = 'Integer';
Optimize(prob.Solver);
varvalue = prob.VarDecision.FinalValue;
The procedural API provides access to each of the
SDK's primary objects through a conventional calling
interface. All procedural calls start with Solver... and the
name or abbreviation of the SDK object, for example Prob, Mod, Var
and Fcn.
_Integer_Type inttype[] = {Integer_Type_Integer,
Integer_Type_Integer};
double objval, x[nvars];
SolverProblem(&prob);
SolverProbTypeSet(prob, Solver_Type_Maximize, Problem_Type_NA);
SolverVariableAdd(prob, L"MyVars", Variable_Type_Decision,
nvars);
SolverFunctionAdd(prob, L"MyCons",
Function_Type_Constraint, ncons);
SolverFunctionAdd(prob, L"MyObj", Function_Type_Objective,
1);
SolverModArrayOrder(prob, Array_Order_ByCol);
SolverModAllLinearSet(prob, Function_Type_Objective,
Variable_Type_All , objcoeff);
SolverModAllLinearSet(prob, Function_Type_Constraint,
Variable_Type_All, concoeff);
SolverFcnUpperBoundSet(prob, L"MyCons", rhsvalue);
SolverVarNonNegative(prob, L"MyVars");
SolverVarIntegerTypeSet(prob, L"MyVars", inttype);
SolverOptimize(prob, &status, &objval);
SolverVarFinalValue(prob, L"MyVars", x);
SolverProbFree(&prob);
Back to Solver
Platform SDK Product Overview