ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 04 Nov 2012 11:51:33 +0100binary linear programminghttps://ask.sagemath.org/question/9499/binary-linear-programming/to whom it may concern
greeting
I have written a binary linear programing. It seems ok.
But the result is
MIPSolverException: 'GLPK : Solution is undefined'
I will appreciate if you can help me and describe the reason
Regards
Aissan Sat, 03 Nov 2012 12:39:15 +0100https://ask.sagemath.org/question/9499/binary-linear-programming/Comment by benjaminfjones for <p>to whom it may concern
greeting </p>
<p>I have written a binary linear programing. It seems ok. </p>
<p>But the result is
MIPSolverException: 'GLPK : Solution is undefined'</p>
<p>I will appreciate if you can help me and describe the reason</p>
<p>Regards
Aissan </p>
https://ask.sagemath.org/question/9499/binary-linear-programming/?comment=18750#post-id-18750It's usually not possible to debug a program without seeing it. If you can edit your question and add a minimal example the recreates your problem then someone can try to help.Sat, 03 Nov 2012 16:50:36 +0100https://ask.sagemath.org/question/9499/binary-linear-programming/?comment=18750#post-id-18750Answer by Aissan Dalvandi for <p>to whom it may concern
greeting </p>
<p>I have written a binary linear programing. It seems ok. </p>
<p>But the result is
MIPSolverException: 'GLPK : Solution is undefined'</p>
<p>I will appreciate if you can help me and describe the reason</p>
<p>Regards
Aissan </p>
https://ask.sagemath.org/question/9499/binary-linear-programming/?answer=14227#post-id-14227this 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( 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)
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()Sun, 04 Nov 2012 11:51:33 +0100https://ask.sagemath.org/question/9499/binary-linear-programming/?answer=14227#post-id-14227