Discrepancy in Objective Function Value Calculation
Awaiting user inputHi,
I'm experiencing a discrepancy in my optimization model's objective function value and its expected value after solving with Gurobi. My objective function is defined as revenue minus total costs. However, when I calculate the expected result based on individual cost components and revenue, I get a different value from what Gurobi reports.
Here's my objective function:
```python
model.setObjective(
revenue  total_costs,
sense=GRB.MAXIMIZE)
```
These are my output values after solving the model:
 Fixed costs: 500000
 Additional capacity costs: 7770.0
 Operational costs: 155400.0
 Charging costs: 171.05
 Total costs: 663341.05
 Total revenue: 280383.04
 Objective function value: 385565.56
When I calculate the expected objective function value as `revenue  total costs`, I get:
280383.04  663341.05 = 382958.01
This differs from the value reported by Gurobi, which is 385565.56. The difference is around 2607.55. I'm trying to understand why this discrepancy exists.
What might be causing this difference between my calculated objective function value and what Gurobi reports?
Any insights or suggestions to resolve this discrepancy would be greatly appreciated. Thank you in advance for your help!

Hi Marith,
How are you getting the below values?
 Fixed costs: 500000
 Additional capacity costs: 7770.0
 Operational costs: 155400.0
 Charging costs: 171.05
 Total costs: 663341.05
 Total revenue: 280383.04Once the model is solved, could you please query the X attribute of the revenue variable (or variables that make up revenue) and the total_cost variable (or variables that make up total_cost)? Their difference should match the objective value.
Best regards,
Simran0
Please sign in to leave a comment.
Comments
1 comment