Commit 66843e69 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

updating to CPLEX 12.8

parent 9c411ba9
......@@ -6,7 +6,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import ilog.concert.IloException;
import ilog.cplex.IloCplex;
import ilog.opl.*;
import vagabond.pieces.*;
import vagabond.reduction.ReduceTo;
......
......@@ -3,7 +3,7 @@ package vagabond.testing;
import org.junit.Test;
import ilog.concert.*;
import ilog.cplex.IloCplex;
import ilog.opl.IloCplex;
/**
* Simple example (provided by IBM, modified by Jonathan Shahen) to try and run a couple tests through CPLEX
......@@ -40,16 +40,12 @@ public class CPLEXTests {
int nvars = x.length;
for (int j = 0; j < nvars; ++j) {
cplex.output().println("Variable " + j +
": Value = " + x[j] +
" Reduced cost = " + dj[j]);
cplex.output().println("Variable " + j + ": Value = " + x[j] + " Reduced cost = " + dj[j]);
}
int ncons = slack.length;
for (int i = 0; i < ncons; ++i) {
cplex.output().println("Constraint " + i +
": Slack = " + slack[i] +
" Pi = " + pi[i]);
cplex.output().println("Constraint " + i + ": Slack = " + slack[i] + " Pi = " + pi[i]);
}
}
cplex.end();
......@@ -83,16 +79,12 @@ public class CPLEXTests {
int nvars = x.length;
for (int j = 0; j < nvars; ++j) {
cplex.output().println("Variable " + j +
": Value = " + x[j] +
" Reduced cost = " + dj[j]);
cplex.output().println("Variable " + j + ": Value = " + x[j] + " Reduced cost = " + dj[j]);
}
int ncons = slack.length;
for (int i = 0; i < ncons; ++i) {
cplex.output().println("Constraint " + i +
": Slack = " + slack[i] +
" Pi = " + pi[i]);
cplex.output().println("Constraint " + i + ": Slack = " + slack[i] + " Pi = " + pi[i]);
}
}
cplex.end();
......@@ -126,16 +118,12 @@ public class CPLEXTests {
int nvars = x.length;
for (int j = 0; j < nvars; ++j) {
cplex.output().println("Variable " + j +
": Value = " + x[j] +
" Reduced cost = " + dj[j]);
cplex.output().println("Variable " + j + ": Value = " + x[j] + " Reduced cost = " + dj[j]);
}
int ncons = slack.length;
for (int i = 0; i < ncons; ++i) {
cplex.output().println("Constraint " + i +
": Slack = " + slack[i] +
" Pi = " + pi[i]);
cplex.output().println("Constraint " + i + ": Slack = " + slack[i] + " Pi = " + pi[i]);
}
}
cplex.end();
......@@ -155,30 +143,24 @@ public class CPLEXTests {
//
// using the IloMPModeler API
static void populateByRow(IloMPModeler model,
IloNumVar[][] var,
IloRange[][] rng) throws IloException {
double[] lb = { 0.0, 0.0, 0.0 };
double[] ub = { 40.0, Double.MAX_VALUE, Double.MAX_VALUE };
String[] varname = { "x1", "x2", "x3" };
static void populateByRow(IloMPModeler model, IloNumVar[][] var, IloRange[][] rng) throws IloException {
double[] lb = {0.0, 0.0, 0.0};
double[] ub = {40.0, Double.MAX_VALUE, Double.MAX_VALUE};
String[] varname = {"x1", "x2", "x3"};
IloNumVar[] x = model.numVarArray(3, lb, ub, varname);
var[0] = x;
double[] objvals = { 1.0, 2.0, 3.0 };
double[] objvals = {1.0, 2.0, 3.0};
model.addMaximize(model.scalProd(x, objvals));
rng[0] = new IloRange[2];
rng[0][0] = model.addLe(model.sum(model.prod(-1.0, x[0]),
model.prod(1.0, x[1]),
model.prod(1.0, x[2])), 20.0, "c1");
rng[0][1] = model.addLe(model.sum(model.prod(1.0, x[0]),
model.prod(-3.0, x[1]),
model.prod(1.0, x[2])), 30.0, "c2");
rng[0][0] = model.addLe(model.sum(model.prod(-1.0, x[0]), model.prod(1.0, x[1]), model.prod(1.0, x[2])), 20.0,
"c1");
rng[0][1] = model.addLe(model.sum(model.prod(1.0, x[0]), model.prod(-3.0, x[1]), model.prod(1.0, x[2])), 30.0,
"c2");
}
static void populateByColumn(IloMPModeler model,
IloNumVar[][] var,
IloRange[][] rng) throws IloException {
static void populateByColumn(IloMPModeler model, IloNumVar[][] var, IloRange[][] rng) throws IloException {
IloObjective obj = model.addMaximize();
rng[0] = new IloRange[2];
......@@ -189,41 +171,29 @@ public class CPLEXTests {
IloRange r1 = rng[0][1];
var[0] = new IloNumVar[3];
var[0][0] = model.numVar(model.column(obj, 1.0).and(
model.column(r0, -1.0).and(
model.column(r1, 1.0))),
0.0, 40.0, "x1");
var[0][1] = model.numVar(model.column(obj, 2.0).and(
model.column(r0, 1.0).and(
model.column(r1, -3.0))),
0.0, Double.MAX_VALUE, "x2");
var[0][2] = model.numVar(model.column(obj, 3.0).and(
model.column(r0, 1.0).and(
model.column(r1, 1.0))),
0.0, Double.MAX_VALUE, "x3");
var[0][0] = model.numVar(model.column(obj, 1.0).and(model.column(r0, -1.0).and(model.column(r1, 1.0))), 0.0,
40.0, "x1");
var[0][1] = model.numVar(model.column(obj, 2.0).and(model.column(r0, 1.0).and(model.column(r1, -3.0))), 0.0,
Double.MAX_VALUE, "x2");
var[0][2] = model.numVar(model.column(obj, 3.0).and(model.column(r0, 1.0).and(model.column(r1, 1.0))), 0.0,
Double.MAX_VALUE, "x3");
}
static void populateByNonzero(IloMPModeler model,
IloNumVar[][] var,
IloRange[][] rng) throws IloException {
double[] lb = { 0.0, 0.0, 0.0 };
double[] ub = { 40.0, Double.MAX_VALUE, Double.MAX_VALUE };
static void populateByNonzero(IloMPModeler model, IloNumVar[][] var, IloRange[][] rng) throws IloException {
double[] lb = {0.0, 0.0, 0.0};
double[] ub = {40.0, Double.MAX_VALUE, Double.MAX_VALUE};
IloNumVar[] x = model.numVarArray(3, lb, ub);
var[0] = x;
double[] objvals = { 1.0, 2.0, 3.0 };
double[] objvals = {1.0, 2.0, 3.0};
model.add(model.maximize(model.scalProd(x, objvals)));
rng[0] = new IloRange[2];
rng[0][0] = model.addRange(-Double.MAX_VALUE, 20.0);
rng[0][1] = model.addRange(-Double.MAX_VALUE, 30.0);
rng[0][0].setExpr(model.sum(model.prod(-1.0, x[0]),
model.prod(1.0, x[1]),
model.prod(1.0, x[2])));
rng[0][1].setExpr(model.sum(model.prod(1.0, x[0]),
model.prod(-3.0, x[1]),
model.prod(1.0, x[2])));
rng[0][0].setExpr(model.sum(model.prod(-1.0, x[0]), model.prod(1.0, x[1]), model.prod(1.0, x[2])));
rng[0][1].setExpr(model.sum(model.prod(1.0, x[0]), model.prod(-3.0, x[1]), model.prod(1.0, x[2])));
x[0].setName("x1");
x[1].setName("x2");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment