sangho park
sangho park

Reputation: 25

How to solve this error when I use CP in Cplex

Now, I am facing with an error.

'Decision variables of type dvar float not supported by this algorithm.'

Here is the code that I made.

I will write it simply.

Firstly, I got in trouble with error that "'q1' is not convex."

So, now i am trying to 'Using CP;'

Using CP;

int a = 2;
int e = 4;
int h = 3;
int t = 6;

range arange = 1..a;
range erange = 1..e;
range hrange = 1..h;
range trange = 1..t;

int nd[erange][hrange] = [[0.8, 0.2, 0.3]
                          [0.3, 0.1, 0.6]
                          [0.1, 0.7, 0.5]];

dvar boolean x[arange][erange][trange];
dvar float y[erange][hrange][trange];

maximize
sum(a in arange, e in erange, h in hrange, t in trange)
  y[e][h][t] * x[a][e][t];

subject to {

forall(a in arange, e in erange, t in trange, h in hrange)
   y[e][h][t] == nd[e][h];

}

I need to use type of 'float' as a decision variable.

But 'Using CP;' does not support this type.

In this case, what should I do to solve this error.

Upvotes: 0

Views: 718

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10062

as can be seen in the example floatexpr.mod you could use decision expressions in order to use decimal values. In your example:

using CP;

int a = 2;
int e = 4;
int h = 3;
int t = 6;

range arange = 1..a;
range erange = 1..e;
range hrange = 1..h;
range trange = 1..t;

float nd[erange][hrange] = [[0.8, 0.2, 0.3],
                          [0.3, 0.1, 0.6],
                          [0.1, 0.7, 0.5]];

int scale=10;                          

dvar boolean x[arange][erange][trange];
dvar int yscale[erange][hrange][trange] in 0..1000;

dexpr float y[a in erange][b in hrange][c in trange]=yscale[a][b][c]/scale;

maximize
sum(a in arange, e in erange, h in hrange, t in trange)
  y[e][h][t] * x[a][e][t];

subject to {

forall(a in arange, e in erange, t in trange, h in hrange)
   (y[e][h][t] - nd[e][h])<=0.01;

}

Upvotes: 1

Related Questions