在 Cplex 中使用 CP 时如何解决此错误
How to solve this error when I use CP in Cplex
现在,我遇到了一个错误。
'Decision variables of type dvar float not supported by this algorithm.'
这是我编写的代码。
我会简单写的
首先,我遇到了“'q1' 不是凸的”错误。
所以,现在我正在尝试 '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];
}
我需要使用 'float' 的类型作为决策变量。
但是'Using CP;'不支持该类型
在这种情况下,我应该如何解决这个错误。
如示例 floatexpr.mod 所示,您可以使用决策表达式来使用十进制值。在您的示例中:
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;
}
现在,我遇到了一个错误。
'Decision variables of type dvar float not supported by this algorithm.'
这是我编写的代码。
我会简单写的
首先,我遇到了“'q1' 不是凸的”错误。
所以,现在我正在尝试 '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];
}
我需要使用 'float' 的类型作为决策变量。
但是'Using CP;'不支持该类型
在这种情况下,我应该如何解决这个错误。
如示例 floatexpr.mod 所示,您可以使用决策表达式来使用十进制值。在您的示例中:
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;
}