问题
I another bug as you can see below:
Error at _cmdno 8 executing "solve" command
(file ./script/runConfiguration.run, line 5, offset 127):
error processing constraint c1a[2,'o1',1]:
unexpected type 0x14205 in ecopy()
I guess that the problem causing comparison with the index (element of set) variable in c1a constraint. Is it possible to avoid this bug?
My new ampl model:
#sets
#-------------------------------------------------------------------------------------
set K; #index of nodes with group of clients
set N; #nodes
set E; #edges
set O; #objects
#parameters
#-------------------------------------------------------------------------------------
param d {K,O}; #demands for object o
param t {K,O} symbolic; #destination nodes
param r {N,K} binary; #1 if node n is ancestor of node k, 0 otherwise
param a {N,E} binary; #1 if edge begins in vertex, 0 otherwise
param b {N,E} binary; #1 if edge ends in vertex, 0 otherwise
param c {E}; #cost of using an edge
param Hmax; #available capacity for allocation object in proxy servers
#variables
#-------------------------------------------------------------------------------------
var f {N,O} binary; #1 if object saved at node k, 0 otherwise
var x {E,K,O}; #value of the demand realised over edge for object
var s {K,O} symbolic in N; #source nodes
#goal function
#-------------------------------------------------------------------------------------
#The function minimizes cost of routing
#By saving copies at CDN proxies we minimizing all traffic from all demands
#with all objects
minimize goal:
sum{e in E}
sum{k in K}
sum{o in O}
(x[e,k,o]*c[e]);
#constraints
#-------------------------------------------------------------------------------------
subject to c1a {k in K, o in O, n in N: n!=t[k,o]}:
(s[k,o]==n)
==>
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) =
d[k,o]*(1-f[k,o]);
subject to c1b {k in K, o in O, n in N: n!=t[k,o]}:
(s[k,o]!=n)
==>
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) =
0;
subject to c1c {k in K, o in O, n in N: n==t[k,o]}:
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) =
-d[k,o]*(1-f[k,o]);
subject to c2:
sum{k in K}
sum{o in O}
f[k,o] <= Hmax;
subject to c3 {k in K, o in O}:
sum{n in N}
r[n,k]*f[n,o] <= 2;
subject to c4 {o in O}:
f[1,o]=1;
subject to c5 {k in K, o in O}:
s[k,o]=
2-sum{n in N}(r[n,k]*f[n,o])
+(sum{n in N}
(r[n,k]*f[n,o])-1)
*(sum{i in K}(r[i,k]*f[i,o]*i));
subject to c0 {e in E, k in K, o in O}:
x[e,k,o]>=0;
and here are very simple data:
#Data file for 'CDN allocation copies' problem simple example
#indices
set K := 2 3 4; #index of nodes with group of clients
set N := 1 2 3 4; #nodes
set E := 1_2 2_3 2_4; #edges
set O := o1; #objects
#parameters
param d (tr): #demands for object o
2 3 4 :=
o1 0 512 512;
#opt= 63 + 75 = 138
param t (tr): #destination nodes
2 3 4 :=
o1 2 3 4;
param r (tr): #1 if node n is ancestor of node k, 0 otherwise
1 2 3 4 :=
2 1 0 0 0
3 1 1 0 0
4 1 1 0 0;
param a (tr): #1 if edge begins in vertex, 0 otherwise
1 2 3 4 :=
1_2 1 0 0 0
2_3 0 1 0 0
2_4 0 1 0 0;
param b (tr): #1 if edge ends in vertex, 0 otherwise
1 2 3 4 :=
1_2 0 1 0 0
2_3 0 0 1 0
2_4 0 0 0 1;
param c := #cost of using an edge
1_2 3
2_3 1
2_4 1;
param Hmax := 1; #available capacity for allocation object in proxy servers
This data file describe network with 4 nodes with topology like this:
1
|
2
/ \
3 4
It is easy to guess that the best solution is to save only the content of the node 2. The object function = 1024 and f_2,o1=1.
Whis model try to solve Strorage Capacity Allocation problem, which I described in another my post: Bug when solving CDN allocation rule
回答1:
I with my friends found solution for redefine CDN SCAP problem as it shown below, which is applicable for CPLEX resolver:
#Model for 'CDN allocation copies' problem
#sets
#-------------------------------------------------------------------------------------
set K; #index of nodes with group of clients
set N; #nodes
set E; #edges
set O; #objects
#parameters
#-------------------------------------------------------------------------------------
param d {K,O}; #demands for object o
param t {K,O} symbolic; #destination nodes
param r {N,K} binary; #1 if node n is ancestor of node k, 0 otherwise
param a {N,E} binary; #1 if edge begins in vertex, 0 otherwise
param b {N,E} binary; #1 if edge ends in vertex, 0 otherwise
param c {E}; #cost of using an edge
param Hmax; #available capacity for allocation object in proxy servers
#variables
#-------------------------------------------------------------------------------------
var f {N,O} binary; #1 if object saved at node k, 0 otherwise
var x {E,K,O} >= 0; #value of the demand realised over edge for object
var s {K,O} binary; #source nodes
#goal function
#-------------------------------------------------------------------------------------
#The function minimizes cost of routing
#By saving copies at CDN proxies we minimizing all traffic from all demands
#with all objects
minimize goal:
sum{e in E}
sum{k in K}
sum{o in O}
(x[e,k,o]*c[e]);
#constraints
#-------------------------------------------------------------------------------------
subject to c1a {k in K, o in O, n in N: n==1}:
s[k,o] = 0
==>
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) -
d[k,o]*(1-f[k,o]) = 0
else
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) =
0;
subject to c1b1 {k in K, o in O, n in N: n!=t[k,o] and n!=1}:
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) -
r[n,k]*d[k,o]*(1-f[k,o]) <= 0;
subject to c1b2 {k in K, o in O, n in N: n!=t[k,o] and n!=1}:
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) -
r[n,k]*d[k,o]*s[k,o] <= 0;
subject to c1b3 {k in K, o in O, n in N: n!=t[k,o] and n!=1}:
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) -
r[n,k]*d[k,o]*f[n,o] <= 0;
subject to c1c {k in K, o in O, n in N: n==t[k,o]}:
sum{e in E}
(a[n,e]*x[e,k,o]) -
sum{e in E}
(b[n,e]*x[e,k,o]) =
-d[k,o]*(1-f[k,o]);
subject to c2:
sum{k in K}
sum{o in O}
f[k,o] <= Hmax;
subject to c3 {k in K, o in O}:
sum{n in N}
r[n,k]*f[n,o] <= 2;
subject to c4 {o in O}:
f[1,o]=1;
subject to c5 {k in K, o in O}:
s[k,o]=sum{n in N}(r[n,k]*f[n,o])-1;
来源:https://stackoverflow.com/questions/16500128/ampl-ecopy-error-causing-by-comparison-indices-element-of-set-with-variable