Re: multiple LpProblem (sub-models)

399 views
Skip to first unread message

nikhil khinchi

unread,
Nov 8, 2014, 1:59:51 PM11/8/14
to pulp-or...@googlegroups.com
Hi, 

I was wondering that is it possible to use multiple sub-problems which can solved sequentially and added together to get larger models/problems

for example 'base0' is a subproblem to which I have added several contraints using the base0 += expr <= rhs and solve for an arbitary objective - (a related does the objective expr has to be added first always or does PulP automatically assigns objective to the one not having a bound or limit on the rhs) 

now I want add more constraints to the same and use it as a new LpProblem 'model', for example if I want to add all the constraints added to base0 to model and solve with a different objective, Is it sytactically correct to use model += base0 (both model and base0 is type LpProblem)

Another query is related to objective, can write the objective expression as an LpVariable 'prodObjective' and then add it the LpProblem class for example base0 += prodObjective

I know it is a lot of queries at the same time. I wanted to avoid a seperate mail, if it is inconvenient please do point out, will ask in seperate posts

Thanks
Nikhil Khinchi
Senior Undergraduate
IIT Delhi

Stuart Mitchell

unread,
Nov 9, 2014, 4:48:58 PM11/9/14
to pulp-or...@googlegroups.com
see below

On Sun, Nov 9, 2014 at 7:59 AM, nikhil khinchi <nikhilk...@gmail.com> wrote:
Hi, 

I was wondering that is it possible to use multiple sub-problems which can solved sequentially and added together to get larger models/problems

for example 'base0' is a subproblem to which I have added several contraints using the base0 += expr <= rhs and solve for an arbitary objective -
 
(a related does the objective expr has to be added first always or does PulP automatically assigns objective to the one not having a bound or limit on the rhs
If you add an LpAffineExpression to the model it becomes the objective at any time, Also you can use LpProblem.setObjective() 

now I want add more constraints to the same and use it as a new LpProblem 'model', for example if I want to add all the constraints added to base0 to model and solve with a different objective, Is it sytactically correct to use model += base0 (both model and base0 is type LpProblem)

use LpProblem.extend()
 def extend(self, other, use_objective = True):
        """
        extends an LpProblem by adding constraints either from a dictionary
        a tuple or another LpProblem object.

        @param use_objective: determines whether the objective is imported from
        the other problem

        For dictionaries the constraints will be named with the keys
        For tuples an unique name will be generated
        For LpProblems the name of the problem will be added to the constraints
        name
        """


Another query is related to objective, can write the objective expression as an LpVariable 'prodObjective' and then add it the LpProblem class for example base0 += prodObjective
Yes this will work 

I know it is a lot of queries at the same time. I wanted to avoid a seperate mail, if it is inconvenient please do point out, will ask in seperate posts

Thanks
Nikhil Khinchi
Senior Undergraduate
IIT Delhi

--
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

nikhil khinchi

unread,
Nov 9, 2014, 9:48:22 PM11/9/14
to pulp-or...@googlegroups.com
Thanks sir for the swift reply. I checked out the setObjective method after posting the query but is it the objective mutable for example if you wanted to use the same set of constraints with a different objective, would'nt that cause an error since an expression without rhs value already exist. 
I believe extend would allow this be to be possible. 

essentially what I am attempting to do is to solve a model (a set of constraints) for one objective (out of list of objectives), extract the value of the objective expression and add it as a constraint with rhs value (nased on the objective's optimal) and resolve it with another objective. 

I noticed LpProblem.sequentialSolve() and several other methods for different pulp classes that are not described in the documentation.Is there a reference sheet or case study on multi-objective optimization in pulp which I can use as reference

Thanks
Nikhil
Senior Undergraduate 
IIT Delhi

--
You received this message because you are subscribed to a topic in the Google Groups "pulp-or-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pulp-or-discuss/XoIq0QuE3WU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pulp-or-discu...@googlegroups.com.

Stuart Mitchell

unread,
Nov 9, 2014, 9:55:18 PM11/9/14
to pulp-or...@googlegroups.com
yes LpProblem.sequentialSolve() is what you want.

the documentation to the function is

    def sequentialSolve(self, objectives, absoluteTols = None,
                        relativeTols = None, solver = None, debug = False):
        """
        Solve the given Lp problem with several objective functions.

        This function sequentially changes the objective of the problem
        and then adds the objective function as a constraint

        :param objectives: the list of objectives to be used to solve the problem
        :param absoluteTols: the list of absolute tolerances to be applied to
           the constraints should be +ve for a minimise objective
        :param relativeTols: the list of relative tolerances applied to the constraints
        :param solver: the specific solver to be used, defaults to the default solver.

        """
It returns a list of the problem statuses

Stu

nikhil khinchi

unread,
Nov 12, 2014, 1:28:44 PM11/12/14
to pulp-or...@googlegroups.com
Sir,

I have few more queries specific to the pulp class usage as listed below

1. I have already hard coded a constraint as an lpSum as follows

for d in D:
    for c in C:
        calibrateArea += lpSum([xcrop0.get((l,t,c,a,fs,p,k),0)*yield1[l,t,c,p,k] for k in K0 for p in P0 for fs in FS
                                for a in A for t in T for l in L if (d,l) in MAP]) <= bprod[d,c]/1000

If I wanted to add it to another problem is possible to do if I store it in a variable, I really doubt it but need confirmation on this.

2. Another Issue of double lpSum, suppose a objective expression defined in terms of lpSum

I have defined as LpVariable 
productionObjective = LpVariable(name='productionObjective', lowBound=None, upBound=None,cat=LpContinuous)

productionObjective = lpSum([lpSum([xcrop0.get((l,t,c,a,fs,p,k),0)*yield1[l,t,c,p,k] for fs in FS for a in A for t in T
                                    for l in L if (d,l) in MAP])/bprod[d,c] for k in K0 for p in P0 for c in C
                             for d in D if bprod[d,c] != 0])


Note: if statement on the bprod[d,c] != 0 to void case where divisibility is not possible

The above definition is giving me an output and no errors. I need confirmation on the same.

3. Another Issue is that when I write the .lp while to inspect the equation visually, I have oberverd in a constraint generation
that when the left hand side expression computes to zero, I get lines like -  _C1020: dummy <= 5.7153774

I suppose these might interfere with solution. I would prefer not having them at all. Please provide inputs on the same.
I suppose these could easily be taken care of through if statement to exclude cases whenever each parameters is zero.

Thanks for the swift replies

Regards
Nikhil
Senior Undergraduate
IIT Delhi

Stuart Mitchell

unread,
Nov 12, 2014, 3:46:46 PM11/12/14
to pulp-or...@googlegroups.com
See below.

On Thu, Nov 13, 2014 at 7:23 AM, nikhil khinchi <nikhilk...@gmail.com> wrote:
Sir,

I have few more queries specific to the pulp class usage as listed below

1. I have already hard coded a constraint as an lpSum as follows

for d in D:
    for c in C:
        calibrateArea += lpSum([xcrop0.get((l,t,c,a,fs,p,k),0)*yield1[l,t,c,p,k] for k in K0 for p in P0 for fs in FS
                                for a in A for t in T for l in L if (d,l) in MAP]) <= bprod[d,c]/1000

If I wanted to add it to another problem is possible to do if I store it in a variable, I really doubt it but need confirmation on this.

I think so, why don't you try it and look at the .lp file produced. 

2. Another Issue of double lpSum, suppose a objective expression defined in terms of lpSum

I have defined as LpVariable 
productionObjective = LpVariable(name='productionObjective', lowBound=None, upBound=None,cat=LpContinuous)

productionObjective = lpSum([lpSum([xcrop0.get((l,t,c,a,fs,p,k),0)*yield1[l,t,c,p,k] for fs in FS for a in A for t in T
                                    for l in L if (d,l) in MAP])/bprod[d,c] for k in K0 for p in P0 for c in C
                             for d in D if bprod[d,c] != 0])


Note: if statement on the bprod[d,c] != 0 to void case where divisibility is not possible

The above definition is giving me an output and no errors. I need confirmation on the same.

Again just do it and see if it works 
 

3. Another Issue is that when I write the .lp while to inspect the equation visually, I have oberverd in a constraint generation
that when the left hand side expression computes to zero, I get lines like -  _C1020: dummy <= 5.7153774

I suppose these might interfere with solution. I would prefer not having them at all. Please provide inputs on the same.

Right these are put in in case the user does something like 0 >= 5

I do have a todo to remove these

Stu

nikhil khinchi

unread,
Nov 14, 2014, 1:10:21 PM11/14/14
to pulp-or...@googlegroups.com
Hi sir, 

There are some Issues with LpProblem.extend() method. I have three submodels base0, calibrateProd and calibrateArea each with their own unique set of constraints, variables and Objective.

calibrateProd and calibrateArea both are extension of base0 and have a LpVariable common with base0 - xcrop0 while calibrateArea has two LpVariable unique to itself - i.e. LpVariable xcrop0 is a global variable.

But when I examine the .lp file the extension the constraints imported from base0 model into the calibrateProd model have base0xcrop_'string' and so on  i.e. the base0 is getting attached with the xcrop decision variable

when I run the script with input to solver the decision variables unique to calibrateArea (areaErrorL and areaErrorU) model have 'None' as an output value.LpVariable method to get optimal value for post optimality analysis and 'None' when I try to print the value(LpProblem.Objective) for LpProblem 'calibrateArea'

I was ablt to get optimal value for xcrop0 variable when I run the calibrateProd LpProblem probably because it has no unique decision variable other the xcrop0 the one it shares with base0 and different objective function though.

PFA, python scripts for different sub-problem and .lp file for different sub-problems.

Do I have to explictly specify that xcrop0, areaErrorL and areaErrorU are decision variables for calibrateArea LpProblem for ex. using calibrateArea.addVariable(areaErrorU). I suspect that that the LpProblem.extend method import the decision variable of the sub-problem. 

Thanks and Regards
Nikhil Khinchi
Senior Undergraduate
IIT Delhi

base0.py
calibrateProd.py
calibrateArea.py
CSAP_base_calibration_replica.lp
Baseline production calibration.lp
Reply all
Reply to author
Forward
0 new messages