Cplex is it possible to write objective function like this

192 views Asked by At

I have a 2d matrix of scores as parameters. I have nxm variables x[i,j], those variables can assume integer values in a predetermined range. I need to maximize something like this: desidered objective function

Where scores is the matrix. Is it possible to define such a objective function?

1

There are 1 answers

0
Alex Fleischer On

2 options as said in How to use a decision variable as an index with CPLEX part of HOW TO WITH OPL CPLEX?

With CPOptimizer in CPLEX

using CP;
range r=1..5;
float value[r]=[2,3,4.5,1,0];
dvar int i in 1..5;
maximize value[i];
subject to
{
}
execute
{
writeln("i=",i);
}

or with CPLEX MIP

range r=1..5;

float value[r]=[2,3,4.5,1,0];
dvar int i in 1..5;

maximize sum(k in r) value[k]*(k==i);
subject to
{

}

execute
{
writeln("i=",i);
}

and with your objective that gives

using CP;

int N=4;
int M=5;

range R=1..10;

int scores[i in R][j in R]=i*j;

dvar int x[0..N+1][0..M] in R;

maximize sum(i in 0..N,j in 0..M) scores[x[i,j],x[i+1,j]];

subject to
{
  
}