Originally posted by: Washout
Hi all,
I am writing some code using the Java API for Cplex 12.3 for the first time and I am having problems in constructing the objective function.
It should look something like:
Sum(for some Trains t)((arrivalTime(t) - departureTime(t) - optimalTravelTime)/optimalTravelTime)
But I am getting an error :
" bad operand types for binary operator '-'
obj = model.sum(obj,(arr
trainIndexdestLoc - dep
trainIndexinitialLoc - optimumTravelTime)/(double)optimumTravelTime);
first type: IloIntVar
second type: IloIntVar"
Here is a snippet of my code
public
void addObjectiveFunction(IloModeler model, IloIntVar[][] arr, IloIntVar[][] dep)
throws IloException
{
try
{ IloNumExpr obj = model.numExpr(); ArrayList<Train> newTrains = rw.getNewTrains();
for(
int i = 0; i < newTrains.size(); i++)
{ Train tr = newTrains.get(i);
int trainIndex = tr.getID();
int initialLoc = 0;
// for down trains, the index of the initial location in the journey
int destLoc = rw.getNumberStations() - 1;
// ID of the last station in the railway
int optimumTravelTime = rw.getDownTravelTime();
if (tr.isUpTrain())
{
// reverse applies for trains in UP direction initialLoc = rw.getNumberStations() - 1; destLoc = 0; optimumTravelTime = rw.getUpTravelTime();
} obj = model.sum(obj,(arr[trainIndex][destLoc] - dep[trainIndex][initialLoc] - optimumTravelTime)/(
double)optimumTravelTime);
}
}
catch (IloException e)
{ System.out.println(
"Error in creating objective function - exception: " + e);
}
}
How do I construct each term properly?
#CPLEXOptimizers#DecisionOptimization