Forming a model inside a function
AnsweredHello Guys, I am trying to code a Python function to build a model inside. The name of the function is SP_define. The function returns the model only. I run the below code. When I print the model I get the number of constraints and vars as you can see. But When I optimize the objective function gets the value of 0 and all the ranges are 0. 
Meanwhile, If I run the internal code of the function that makes the model as autonomous lines of code I get a different optimization result when I optimize:
Do you have any idea of what could be going wrong? I am using the line SPmodel.update() before the return SPmodel.
Kind regards
Iason
-
Hi Iason,
I think we'll need to see some code... both the function where you create the model, and where you call it.
- Riley
0 -
Hi Riley I found out my bug. Instead of writing SPmodel.optimize() I should write a subproblem.optimize() since the SPmodel is lying inside the function, while the subproblem is the variable that the function passes the model. Sorry for the confusion.
Kind regards
Iason0 -
No problem, well done on spotting it.
- Riley
0
Please sign in to leave a comment.
Comments
3 comments