Menu

Error when changing the minimization objective

Help
2017-02-15
2018-03-08
  • Julia Helmecke

    Julia Helmecke - 2017-02-15

    Hallo PyMathProg Team,

    first thanks for this awesome update! Unfortunately, I ran in some errors while trying to update my programm (metano.tu-bs.de) to the newest version of pymprog...
    I am trying to describe it as simple as I can:
    The flux balance analysis works pretty good with pymprog 1.0, unless I try to reset the objective function by running

    min(sum(self.glpkVar[i]*0. for i in self.objIndices),
                               "objective")
    

    and afterwards I set a new objective with this code:

    objIndices = [i for i in range(len(obj)) if obj[i] != 0.]
    min(sum(self.glpkVar[i]*obj[i] for i in objIndices),
                               "objective")
    

    Then I am trying to solve the model and it gives me the following error message:

    Traceback (most recent call last):
      File "fba.py", line 804, in <module>
        main()
      File "fba.py", line 775, in main
        options.minimizeFlux, not options.useFullMatrix)
      File "fba.py", line 663, in runOnModel
        lbSplit, ubSplit, fbaParams)
      File "fba.py", line 379, in run
        s = ps.minimize()[1]
      File "/home/jhe/metano/metano-1.1-devel/src/linearproblem.py", line 237, in minimize
        self.glpkP.solve()
      File "/usr/local/lib/python2.7/dist-packages/pymprog.py", line 5259, in solve
        me.update_lazy() #this takes care of rebuilding
      File "/usr/local/lib/python2.7/dist-packages/pymprog.py", line 4443, in update_lazy
        e.update(me) 
      File "/usr/local/lib/python2.7/dist-packages/pymprog.py", line 831, in update
        for i, c in expr.mat:
    AttributeError: 'float' object has no attribute 'mat'
    

    When I am not trying to change the objective everything works just fine and the solver gives me the right result, so I thing there is an issue with the new update function? Hopefully you have some suggestions for me to solve the problem.

    Thanks in advance and best regards,
    Julia Helmecke

     

    Last edit: Julia Helmecke 2017-02-15
  • Yingjie Lan

    Yingjie Lan - 2017-03-28

    Hi Julia,

    Sorry for the late response, it seems that problem is caused by a bad objective function: your objective is only a constant (i.e. the coefficients for all variables are zero).

    Regards,
    Yingjie

     
  • Julia Helmecke

    Julia Helmecke - 2017-04-29

    Hello Yingjie,

    thank you for your answer. Indeed, the program resets the objective value by giving an empty vector (all values are zero), since this was necessary in older pymprog versions. I have deleted this function and now the program runs without any error messages. The problem is, that it always returns an infeasible solution. Let me make it more clear: when I run the script for only one reaction of my model (the reaction is set as objective function), it works properly. But when I iterate through all reactions in the model and set them as objective function, it returns an unfeasible solution, even with the same values given in the single run.

    My question is now: how do I reset the old objective function (if necessary) and set a new one? If you need a minimal working example, just let me now. You can also install metano via pip (see metano.tu-bs.de) and run the fva.py script to see my issue.

    Best regards,
    Julia

     
  • Yingjie Lan

    Yingjie Lan - 2017-06-12

    Hi Julia,

    Sorry again for the late response, I should check it more often seriously. The usual way to modify your objective coeficients is to use parameters, you may look at this example:

    http://pymprog.sourceforge.net/advanced.html#assign

    I tried the fva.py script, but it requres options to start running. Can you give me a commandline with options so that I can replicate the problem?

    Regards,
    Yingjie

     
  • Julia Helmecke

    Julia Helmecke - 2017-08-22

    Hallo Yingjie,

    I have solved the problem now. There was an issue in the first definition of the flux variable. I did not set both boundaries to None, so the default lower and upper bound was 0 and inf, respectively. This was not an issue in previous versions, so maybe you changed the default bounds in the var() function? If so, consider to include it in the "A word on compatability" section on your website. :)
    However, thank you for your help with my objective function issue. Now everything works fine again.

    Best regards,
    Julia

     
  • Yingjie Lan

    Yingjie Lan - 2018-03-08

    Hi Julia,

    thanks for letting me know things worked out well in the end. And I will document it to help others out who might encounter similar problems, I suppose this is from really old version of pymprog.

    Best regards,
    Yingjie

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.