Ask Your Question

Aissan Dalvandi's profile - activity

2022-03-07 14:32:41 +0200 received badge  Popular Question (source)
2021-09-01 18:41:12 +0200 received badge  Popular Question (source)
2020-06-10 06:36:45 +0200 received badge  Taxonomist
2016-08-18 17:35:11 +0200 received badge  Student (source)
2015-11-06 09:23:31 +0200 received badge  Self-Learner (source)
2015-11-06 09:23:31 +0200 received badge  Teacher (source)
2015-11-06 06:47:16 +0200 answered a question solver_parameter('timelimit') doesnt work

Its working but its based on computation time, NOT execution time. However, still not sure about the relation between these two!

2015-11-06 03:49:20 +0200 received badge  Autobiographer
2015-11-06 03:37:46 +0200 answered a question How to upgrade Sage 6.9 to latest beta version?

I did the following:

sudo apt-add-repository -y ppa:aims/sagemath
sudo apt-get update
sudo apt-get install sagemath-upstream-binary
2015-11-06 03:24:44 +0200 asked a question Execution time vs. Computation time in MILP

Hi,

I am using GLPK in Sage 6.9 to solve MILP problem. I am also using the Solver_parameter('timelimit') to terminate the problem after the specficied time. According to SageMath documentation, "timelimit" defines the maximum time spent on a computation. Measured in seconds. However, I am a bit confused with this definition. This is because:

I am solving the same problem with the same timelimit value for different input values (generated randomly using uniform distribution) while I was printing execution time of each. I have noticed different execution times when I am giving different inputs (ranging from 1min, 5mins, to even 10mins).

Can some one please tell me how the computation time is calculated for timelimit? Why they are different even though I used the same problem with the same timelimit? Is it something related to the size of the input, as its only difference between them? Is there any relation between computation and execution times?

Cheers, Aissan

2015-11-04 05:57:39 +0200 answered a question calling MixedIntegerLinearProgram gives AssertionError: The given source does not contain 'def'. How to fix this?

It works fine in my computer. Try to re-install the sage via binary. I guess you can use the following:

apt-add-repository -y ppa:aims/sagemath
apt-get update
apt-get install sagemath-upstream-binary
2015-11-04 04:00:47 +0200 received badge  Editor (source)
2015-11-04 03:49:27 +0200 commented answer solver_parameter('timelimit') doesnt work

I am actually printing the timelimit and it affected. However, it keeps running unless I manually interrupt it.

Here is my code:

p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")

p.solver_parameter( "timelimit", 60)

Z =    p.new_variable ( binary= True)

#### defining all the variables and constrains here #####

p.set_objective(   p.sum(COSTPenalty * (1-Z[k])   for k in   Requests.keys()))

b= p.get_backend()

print (p.solver_parameter( 'timelimit'))

try :

    p.solve() 

    return (p.get_objective_value() )

except MIPSolverException:

    b= p.get_backend()

    print ('the best known objective bound is ',b.best_known_objective_bound())

    return b.best_known_objective_bound()

Thanks a lot!

2015-11-03 07:47:45 +0200 asked a question solver_parameter('timelimit') doesnt work

Hi,

I have an MILP problem and trying to solve it with Sage, GLPK solver. As I want to terminate the problem before getting the optimum answer, I am using the p.solver_parameter("timelimit", 60). I have also used

    try:
        p.solve() 
    except MIPSolverException:
        b = p.get_backend()
        print('best known opjective bound', b.best_known_objective_bound())

However, the solver doesn't stop!!! It keeps runing. I guess the time limit part doesn't work. Its interesting that the p.solver_parameter("time limit") its affected, as I am printing its value before passing the p.solve(). I have also tried p.solver_parameter( backend.glp_simplex_or_intopt, backend.glp_intopt_only) and printed the p.solver_parameter("time limit_intopt"). It's printing 60000 which is right. I have no idea why it keeps running.

Could anyone help me with this issue?

Thanks in advance,

Cheers, Aissan

2015-10-31 09:04:11 +0200 commented answer best_known_objective_bound()

Yes :) you are right. Sorted :)

Many thanks

2015-10-31 09:03:40 +0200 received badge  Scholar (source)
2015-10-31 06:35:44 +0200 received badge  Organizer (source)
2015-10-31 05:55:14 +0200 asked a question best_known_objective_bound()

Hi,

I am using sage Version 6.5, Release Date: 2015-02-17. I have MILP problem and trying to solve it. However, I defined time limit and used try and except to get the best_known_objective_bound(). Unfortunately, I am getting AttributeError: 'sage.numerical.backends.glpk_backend.GLPKBackend' object has no attribute 'best_known_objective_bound'

I even tried the following simple example (posted here http://doc.sagemath.org/html/en/refer...). However, I am facing the same issue for the example as well.

sage: g = graphs.CubeGraph(9)

sage: p = MixedIntegerLinearProgram(solver="GLPK")

sage: p.solver_parameter("mip_gap_tolerance",100)

sage: b = p.new_variable(binary=True)

sage: p.set_objective(p.sum(b[v] for v in g))

sage: for v in g:

....: p.add_constraint(b[v]+p.sum(b[u] for u in g.neighbors(v)) <= 1)

sage: p.add_constraint(b[v] == 1) # Force an easy non-0 solution

sage: p.solve() # rel tol 100

1.0

sage: backend = p.get_backend()

sage: backend.best_known_objective_bound() # random

AttributeError: 'sage.numerical.backends.glpk_backend.GLPKBackend' object has no attribute 'best_known_objective_bound'

What I want is to get the best known optimum answer by time limit. Anyone knows how should i get it?

Thanks a lot! Cheers, Aissan

2012-11-13 07:23:59 +0200 asked a question python -sage

Hi

I am have an optimization problem, when I run it for small amount of input it is ok , but for large input, It give : KeyboardInterrupt I will appreciate if one can help me ?

the error is

Traceback (most recent call last):
  File "final2.py", line 181, in <module>
    scheduling.add_constraint(Sum(A[s][d][k][o][p][t] for p in range (_sage_const_0 ,V)) <=_sage_const_1  )
  File "mip.pyx", line 2168, in sage.numerical.mip.Sum (sage/numerical/mip.c:12041)
  File "final2.py", line 181, in <genexpr>
    scheduling.add_constraint(Sum(A[s][d][k][o][p][t] for p in range (_sage_const_0 ,V)) <=_sage_const_1  )
KeyboardInterrupt
2012-11-04 11:51:33 +0200 answered a question binary linear programming

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 ...
(more)
2012-11-03 12:39:15 +0200 asked a question 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