Ask Your Question

Revision history [back]

this my code, it is too long, so, I hope that you can understand it :

scheduling=MixedIntegerLinearProgram(maximization=false )

from sage.numerical.mip import Sum

variables

f = scheduling.new_variable (dim=4, binary=true)

f is the source to destination in time t

l = scheduling.new_variable (dim=4, binary=true) #L id 0 if link op not selected for demand k in time t

A = scheduling.new_variable(dim=6,binary=true) # A is binary s to d in link op in time t for demand k z_op=scheduling.new_variable(dim=2,binary=true) #Z is 1 if is link op is on y = scheduling.new_variable(dim=1,binary=true)

parameters

Num_demand_slice= 1 #number of the time slice

power_link_op= matrix ([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]) # power of the link op that is considered as cost

demand_traffic_kt = matrix ([1]); # 0/1 matrix if demand has traffic in t is 1

rate_k= [2]; #rate of the trafic of the demand k

link_capacity_op= matrix ([[0,0,30,30,30],[0,0,30,30,30],[30,30,0,0,0],[30,30,0,0,0],[30,30,0,0,0]]) # zero if not exist this link in graph, others capacity of that 5 or 6 (not binary matrix) power_sw_o= [[0,0,2,2,2]] #power of the sw o if is zero means that it is server V=5 K=1 B=Num_demand_slice * K

constraint

v is the num of the node

K is the num of the node

for o in range (0,V): for p in range (0,V): if (link_capacity_op[o][p]==0): for t in range (0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint(l[o][p][k][t]==0)

for t in range (0,Num_demand_slice ): for k in range (0,K): if demand_traffic_kt[k][t]==0 : for s in range (0,V ): for d in range (0,V ): scheduling.add_constraint(f[s][d][k][t]==0)

for t in range (0,Num_demand_slice ): for k in range (0,K): if demand_traffic_kt[k][t]==0 : for o in range (0,V ): for p in range (0,V ): scheduling.add_constraint(l[o][p][k][t]==0)

for t in range(0,Num_demand_slice): for d in range(0,V ): for k in range(0,K ): for o in range(0,V ): for p in range(0,V ): for s in range(0,Num_demand_slice ): scheduling.add_constraint(f[s][d][k][t] + l[o][p][k][t]- 1 <= A[s][d][k][o][p][t])

for t in range(0,Num_demand_slice ): for d in range(0,V ): for k in range(0,K ): for o in range(0,V ): for p in range(0,V ): for s in range(1,Num_demand_slice+1 ): scheduling.add_constraint(f[s][d][k][t] + l[o][p][k][t] >= 2* A[s][d][k][o][p][t])

for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if s==o : scheduling.add_constraint(rate_k[k]demand_traffic_kt[k][t](Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == rate_k[k] * demand_traffic_kt[k][t])

for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if d==o : scheduling.add_constraint(rate_k[k]* demand_traffic_kt[k][t](Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == - rate_k[k]demand_traffic_kt[k][t])

for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if (s!=o and d!=o): scheduling.add_constraint(rate_k[k]* demand_traffic_kt[k][t]*(Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == 0)

for t in range(0,Num_demand_slice):

# for o in range(0,V): # for k in range (0,K): # scheduling.add_constraint( 2Sum(rate_k[k] demand_traffic_kt[k][t] * l[o][p][k][t] for p in range (0,V)) \ # - Sum(Sum(rate_k[k] * demand_traffic_kt[k][t]* A[o][d][k][o][p][t] for p in range (0,V)) for d in range (0,V))\ # - Sum(Sum(rate_k[k] * demand_traffic_kt[k][t] * A[d][o][k][o][p][t]for p in range (0,V))for d in range (0,V))\ # - 2* Sum(rate_k[k]* demand_traffic_kt[k][t] * l[p][o][k][t] for p in range(0,V))\ # + Sum(Sum(rate_k[k]* demand_traffic_kt[k][t]* A[s][o][k][p][o][t] for p in range (0,V)) for s in range (0,V)) \ # + Sum (Sum (rate_k[k]* demand_traffic_kt[k][t] * A[o][d][k][p][o][t] for p in range(0,V)) for d in range (0,V)) ==\ # - rate_k[k] * demand_traffic_kt[k][t] * Sum(f[s][o][k][t] for s in range (0,V)) \ # - rate_k[k] * demand_traffic_kt[k][t] * Sum(f[o][d][k][t] for d in range (0,V))) #

for t in range(0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint (Sum(f[s][s][k][t] for s in range(0,V))== 0)

for t in range(0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint(Sum (Sum(f[s][d][k][t] for s in range (0,V)) for d in range(0,V)) == demand_traffic_kt[k][t])

for t in range(0,Num_demand_slice):
for o in range (0,V): for p in range (0,V): scheduling.add_constraint(Sum( (rate_k[k] * l[o][p][k][t]) for k in range (0,K)) <= link_capacity_op[o][p])

for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): scheduling.add_constraint(z_op[o][p] >= l[o][p][k][t])

for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): for i in range (0,B): scheduling.add_constraint(z_op[o][p]- l[o][p][k][t]<= +Infinity * y[i])

for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): for i in range (0,B): scheduling.add_constraint(z_op[o][p]- l[o][p][k][t]>= -Infinity * y[i])

for t in range(0,Num_demand_slice):
scheduling.add_constraint(Sum(Sum(Sum( f[s][d][k][t] for s in range (0,V)) for d in range (0,V)) for k in range (0,K))\ == sum(demand_traffic_kt[k][t] for k in range(0,K)))

scheduling.add_constraint(Sum(y[i] for i in range (0,B)) <= B-1)

optimization function

scheduling.set_objective(sum(sum(z_op[o][p] * ( power_sw_o[o] + power_link_op[o][p]) for o in range(0,V)) for p in range(0,V)))

scheduling.set_objective(Sum(Sum(Sum(Sum(l[o][p][k][t] * power_link_op[o][p] for o in range(0,V)) for p in range(0,V)) \

for k in range (0,K)) for t in range (0,Num_demand_slice)))

scheduling.solve()

click to hide/show revision 2
No.2 Revision

this my code, it is too long, so, I hope that you can understand it :

scheduling=MixedIntegerLinearProgram(maximization=false )

) from sage.numerical.mip import Sum

variables

Sum #####variables f = scheduling.new_variable (dim=4, binary=true)

f binary=true) #f is the source to destination in time t

t l = scheduling.new_variable (dim=4, binary=true) #L id 0 if link op not selected for demand k in time t

A = scheduling.new_variable(dim=6,binary=true) # A is binary s to d in link op in time t for demand k z_op=scheduling.new_variable(dim=2,binary=true) #Z is 1 if is link op is on y = scheduling.new_variable(dim=1,binary=true)

parameters

scheduling.new_variable(dim=1,binary=true) #####parameters Num_demand_slice= 1 #number of the time slice

slice power_link_op= matrix ([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]) # power of the link op that is considered as cost

demand_traffic_kt = matrix ([1]); # 0/1 matrix if demand has traffic in t is 1

rate_k= [2]; #rate of the trafic of the demand k

link_capacity_op= matrix ([[0,0,30,30,30],[0,0,30,30,30],[30,30,0,0,0],[30,30,0,0,0],[30,30,0,0,0]]) # zero if not exist this link in graph, others capacity of that 5 or 6 (not binary matrix) power_sw_o= [[0,0,2,2,2]] #power of the sw o if is zero means that it is server V=5 K=1 B=Num_demand_slice * K

constraint

K #####constraint # v is the num of the node

node # K is the num of the node

node for o in range (0,V): for p in range (0,V): if (link_capacity_op[o][p]==0): for t in range (0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint(l[o][p][k][t]==0)

scheduling.add_constraint(l[o][p][k][t]==0) for t in range (0,Num_demand_slice ): for k in range (0,K): if demand_traffic_kt[k][t]==0 : for s in range (0,V ): for d in range (0,V ): scheduling.add_constraint(f[s][d][k][t]==0)

scheduling.add_constraint(f[s][d][k][t]==0) for t in range (0,Num_demand_slice ): for k in range (0,K): if demand_traffic_kt[k][t]==0 : for o in range (0,V ): for p in range (0,V ): scheduling.add_constraint(l[o][p][k][t]==0)

scheduling.add_constraint(l[o][p][k][t]==0) for t in range(0,Num_demand_slice): for d in range(0,V ): for k in range(0,K ): for o in range(0,V ): for p in range(0,V ): for s in range(0,Num_demand_slice ): scheduling.add_constraint(f[s][d][k][t] + l[o][p][k][t]- 1 <= A[s][d][k][o][p][t])

A[s][d][k][o][p][t]) for t in range(0,Num_demand_slice ): for d in range(0,V ): for k in range(0,K ): for o in range(0,V ): for p in range(0,V ): for s in range(1,Num_demand_slice+1 ): scheduling.add_constraint(f[s][d][k][t] + l[o][p][k][t] >= 2* A[s][d][k][o][p][t])

A[s][d][k][o][p][t]) for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if s==o : scheduling.add_constraint(rate_k[k]demand_traffic_kt[k][t](Sum(A[s][d][k][o][p][t] scheduling.add_constraint(rate_k[k]*demand_traffic_kt[k][t]*(Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == rate_k[k] * demand_traffic_kt[k][t])

for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if d==o : scheduling.add_constraint(rate_k[k]* demand_traffic_kt[k][t](Sum(A[s][d][k][o][p][t] demand_traffic_kt[k][t]*(Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == - rate_k[k]demand_traffic_kt[k][t])

rate_k[k]*demand_traffic_kt[k][t]) for t in range(0,Num_demand_slice ): for k in range(0,K): for s in range (0,V ): for d in range (0,V ): for o in range (0,V ): if (s!=o and d!=o): scheduling.add_constraint(rate_k[k]* demand_traffic_kt[k][t]*(Sum(A[s][d][k][o][p][t] for p in range(0,V))\ - Sum(A[s][d][k][p][o][t] for p in range (0,V))) == 0)

for t in range(0,Num_demand_slice):

0) #for t in range(0,Num_demand_slice): # for o in range(0,V): # for k in range (0,K): # scheduling.add_constraint( 2Sum(rate_k[k] 2*Sum(rate_k[k]* demand_traffic_kt[k][t] * l[o][p][k][t] for p in range (0,V)) \ # - Sum(Sum(rate_k[k] * demand_traffic_kt[k][t]* A[o][d][k][o][p][t] for p in range (0,V)) for d in range (0,V))\ # - Sum(Sum(rate_k[k] * demand_traffic_kt[k][t] * A[d][o][k][o][p][t]for p in range (0,V))for d in range (0,V))\ # - 2* Sum(rate_k[k]* demand_traffic_kt[k][t] * l[p][o][k][t] for p in range(0,V))\ # + Sum(Sum(rate_k[k]* demand_traffic_kt[k][t]* A[s][o][k][p][o][t] for p in range (0,V)) for s in range (0,V)) \ # + Sum (Sum (rate_k[k]* demand_traffic_kt[k][t] * A[o][d][k][p][o][t] for p in range(0,V)) for d in range (0,V)) ==\ # - rate_k[k] * demand_traffic_kt[k][t] * Sum(f[s][o][k][t] for s in range (0,V)) \ # - rate_k[k] * demand_traffic_kt[k][t] * Sum(f[o][d][k][t] for d in range (0,V))) #

# for t in range(0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint (Sum(f[s][s][k][t] for s in range(0,V))== 0)

0) for t in range(0,Num_demand_slice): for k in range (0,K): scheduling.add_constraint(Sum (Sum(f[s][d][k][t] for s in range (0,V)) for d in range(0,V)) == demand_traffic_kt[k][t])

demand_traffic_kt[k][t]) for t in range(0,Num_demand_slice):
for o in range (0,V): for p in range (0,V): scheduling.add_constraint(Sum( (rate_k[k] * l[o][p][k][t]) for k in range (0,K)) <= link_capacity_op[o][p])

for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): scheduling.add_constraint(z_op[o][p] >= l[o][p][k][t])

for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): for i in range (0,B): scheduling.add_constraint(z_op[o][p]- l[o][p][k][t]<= +Infinity * y[i])

y[i]) for t in range(0,Num_demand_slice):
for k in range (0,K): for o in range (0,V): for p in range (0,V): for i in range (0,B): scheduling.add_constraint(z_op[o][p]- l[o][p][k][t]>= -Infinity * y[i])

y[i]) for t in range(0,Num_demand_slice):
scheduling.add_constraint(Sum(Sum(Sum( f[s][d][k][t] for s in range (0,V)) for d in range (0,V)) for k in range (0,K))\ == sum(demand_traffic_kt[k][t] for k in range(0,K)))

range(0,K))) scheduling.add_constraint(Sum(y[i] for i in range (0,B)) <= B-1)

optimization function

B-1) #####optimization function scheduling.set_objective(sum(sum(z_op[o][p] * ( power_sw_o[o] + power_link_op[o][p]) for o in range(0,V)) for p in range(0,V)))

scheduling.set_objective(Sum(Sum(Sum(Sum(l[o][p][k][t] range(0,V))) #scheduling.set_objective(Sum(Sum(Sum(Sum(l[o][p][k][t] * power_link_op[o][p] for o in range(0,V)) for p in range(0,V)) \

for \ #for k in range (0,K)) for t in range (0,Num_demand_slice)))

scheduling.solve()

(0,Num_demand_slice))) scheduling.solve()