adding an elastic constraint

1,108 views
Skip to first unread message

Anthony Anderson

unread,
Jul 29, 2014, 6:01:50 PM7/29/14
to pulp-or...@googlegroups.com
Hello,

I'm interested in solving an IP problem, laid out as follows:

>>> prob = LpProblem("test", LpMinimize)
>>> x = LpVariable.dict("choice", range(1,10), lowbound=0, upbound=1, LpInteger)
>>> prob += sum(c[i]*x[i] for i in range(1,10)), "objective"


I would like to add an elastic constraint to prob, which is necessary for ensuring feasibility. Is it correct to "add" it as prob += elastic_contraint? 

Based on the documentation, I've tried the following:

>>> e = LpAffineExpression([(x[i],a[i]) for i in range(1,10)])
>>> c = LpConstraint(e, "constraint", sense=0, rhs=b)
>>> prob += c.makeElasticSubproblem(penalty=0, proportionFreeBound=0.05)

I just need some clarity on the last line, which produces the following error:

TypeError: Can only add LpConstraintVar, LpConstraint, LpAffineExpression or True objects

Thanks!

Stuart Mitchell

unread,
Jul 31, 2014, 6:00:22 PM7/31/14
to pulp-or...@googlegroups.com
hi use prob.extend() instead

I'll have a look at changing the documentation

Stu


--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Anthony Anderson

unread,
Jul 31, 2014, 6:26:48 PM7/31/14
to pulp-or...@googlegroups.com
I see what you mean. So something like the following:

>>> e = LpAffineExpression([(x[i],a[i]) for i in range(1,10)])
>>> c = LpConstraint(e, "constraint", sense=0, rhs=b)
>>> prob.extend(c.makeElasticSubproblem(penalty=0, proportionFreeBound=0.05))

Thanks for the help.

Anthony.

Stuart Mitchell

unread,
Jul 31, 2014, 6:31:40 PM7/31/14
to pulp-or...@googlegroups.com
yup

Reply all
Reply to author
Forward
0 new messages