Originally posted by: davidoff
On your example, if you simply switch array[0] and array[1] , putting the IloIntVar as the first element of the array, you will get an exception :
java.lang.ClassCastException: [Lilog.concert.IloNumVar; incompatible with [Lilog.concert.IloIntVar;
The reason is that method scalProd will try to conver the array of variables to an array of integer variables. See the implementation of method scalProd (thanks to the decompiler for those who are using IntelliJ version 14):
public IloLinearNumExpr scalProd(double[] vals, IloNumVar[] vars, int start, int num) throws IloException {
ilog.concert.cppimpl.IloNumExpr expr;
if(IloConcertUtils.isIntVarArray(vars)) {
expr = new ilog.concert.cppimpl.IloNumExpr(concert_wrap.IloScalProd(IloConcertUtils.ToCppIloNumArray(this.getEnvImpl(), vals, start, num), IloConcertUtils.ToCppIloIntVarArray(this.getEnvImpl(), (IloIntVar[])((IloIntVar[])vars), start, num)));
} else {
expr = new ilog.concert.cppimpl.IloNumExpr(concert_wrap.IloScalProd(IloConcertUtils.ToCppIloNumArray(this.getEnvImpl(), vals, start, num), IloConcertUtils.ToCppIloNumVarArray(this.getEnvImpl(), vars, start, num)));
}
return expr;
}
And method isIntVarArray is implemeted as:
public static boolean isIntVarArray(IloNumVar[] vars) {
return vars.length > 0 && vars[0] instanceof IloIntVar;
}
#DecisionOptimization#MathematicalProgramming-General