biosustain / cameo

cameo - computer aided metabolic engineering & optimization
http://cameo.bio
Apache License 2.0
113 stars 44 forks source link

Solver do not return expected result #111

Closed MuhammedHasan closed 7 years ago

MuhammedHasan commented 7 years ago

I started to learn cameo and tried following code.

from cobra import Model, Metabolite, Reaction
from cameo.core.solver_based_model import to_solver_based_model

# max cone * cone_margin + popsicle * popsicle margin
# subject to
# cone * cone_cost + popsicle * popsicle_cost <= budget

cone_selling_price = 7.
cone_production_cost = 3.
popsicle_selling_price = 2.
popsicle_production_cost = 1.
starting_budget = 100.

cone = Reaction("cone")
popsicle = Reaction("popsicle")

# constrainted to a budget
budget = Metabolite("budget")
budget._constraint_sense = "L"
budget._bound = starting_budget

cone.add_metabolites({budget: cone_production_cost})
popsicle.add_metabolites({budget: popsicle_production_cost})

# objective coefficient is the profit to be made from each unit
cone.objective_coefficient = \
    cone_selling_price - cone_production_cost
popsicle.objective_coefficient = \
    popsicle_selling_price - popsicle_production_cost

m = Model("lerman_ice_cream_co")
m.add_reactions((cone, popsicle))

solver_model = to_solver_based_model(m)

solution_cameo = solver_model.solve()
solution_cobra = m.optimize()

print(solution_cobra.f)
print(solution_cameo.f)

Output:

133.33333333333334
0.0

Cobra and cameo result are different. cameo do not solve the problem. Did I do something wrong?

KristianJensen commented 7 years ago

Hi Muhammed

You didn't do anything wrong. However, cameo does not support changing the constraint sense and bounds of a metabolite. A metabolite will always correspond to an equality constraint with 0 on the right hand side, as a result of the steady state assumption (S*v = 0). As far as I know these features will also be deprecated in cobrapy in the future.

If you are interested in doing metabolic modeling I suggest you simply disregard the above example, as it has very little to do with metabolism. If you want to solve optimization problems not related to metabolism you might want to take a look at http://github.com/biosustain/optlang (also used as a backend for cameo), which provides a simple interface for formulating and solving optimizations.

MuhammedHasan commented 7 years ago

Thank for your help,

I see this example in cobrapy doc and I ask just for learning although I work on metabolic networks.