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
-
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
Please sign in to leave a comment.
Comments
1 comment