How to extract numerical values from the LinExpr objects
AnsweredHi,
I want to formulate an objective function to calculate VaR.
I get errors when I try to run the following code:
simulated_losses list contains Gurobi LinExpr objects. I do not know how to extract numerical values from the LinExpr objects in this case. I tried
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
You are creating the Gurobi model when defining the list simulated_lossed. That means there is no solution value for the x variables. Mathematical operations on the x-variables give you linear expressions. But getValue() is not possible as long as the model is not solved.
Hence, the list simulated_lossed contains linear expressions that depend on the model variables x.
Now, you can define linear constraints on the expressions. In the documentation Constraints - Gurobi Optimization you can see which type of constraints are possible and can be added to a Gurobi model.
You can define for example min and max constraints (see also Model.addGenConstrMin() and Model.addGenConstrMax() ). But there is no such thing as a sorting constraint.
So what you try to achieve is not possible.
Try to formulate your problem with variables and constraints based on the documentation Variables and Constraints and Objectives.0
Post is closed for comments.
Comments
2 comments