The change of the objective function leads to the error of "callgurobi"
AnsweredI tried to finish economic dispatch of power system by matlab,yalmip,and gurobi.
For example,my objective function is A+B+C+D and the operation of my codes has no errors, when I gave another part E of objective function and there is not any change in the codes,the new objective function is A+B+C+D+E.
Many errors appeared.
error using gurobi
Incorrect size(model.start)
error using callgurobi (第 20 行)
result = gurobi(model,model.params);
error using solvesdp (第 368 行)
eval(['output = ' solver.call '(interfacedata);']);
error using optimize (第 31 行)
[varargout{1:nargout}] = solvesdp(varargin{:});
出错 Copy_of_Success_ACOPF_with_es2 (第 386 行)
sol=optimize(cons,obj,ops);
why??
-
Hi Hao Wen,
The error you're encountering when modifying your optimization objective function in MATLAB using YALMIP and Gurobi is often related to a mismatch or inconsistency in the "start values" (model.start
) provided to the solver. Let's break this down and explore the solutions:Causes of the Issue
-
Initial Solution (model.start):
- If you're using an initial solution (
model.start
) with the Gurobi solver, the size or structure of this array must match the number of variables in the model. AddingE
to your objective function likely introduces new variables or modifies the model structure, making the existingmodel.start
invalid.
- If you're using an initial solution (
-
Solver Cache Issues:
- Gurobi may be trying to use cached values (like a presolve structure) that are incompatible with the modified model.
-
YALMIP Configuration or Parsing:
- Sometimes, modifying the objective function can lead to incomplete updates in the internal YALMIP representation, especially if
optimize
does not reconstruct the model fully.
- Sometimes, modifying the objective function can lead to incomplete updates in the internal YALMIP representation, especially if
Solutions to the Problem
-
Clear the Initial Solution:
- If you are setting a start value (
model.start
) explicitly, ensure it matches the new problem dimensions after addingE
. Alternatively, clear it:model.start = [];
- If you are setting a start value (
-
Rebuild the Model:
- To ensure the model is reconstructed properly, clear and redefine the constraints and objective. For instance:
obj = A + B + C + D + E; cons = [ /* redefine your constraints here */ ]; sol = optimize(cons, obj, options);
- To ensure the model is reconstructed properly, clear and redefine the constraints and objective. For instance:
-
Verify Variable Mapping:
- Ensure the variables added by
E
are correctly defined and included in the optimization model.
- Ensure the variables added by
-
Check Solver Options:
-
If the error persists, try resetting or adjusting solver-specific options. In Gurobi, you might need to reset the parameters or ensure no start values are assumed.
Example for clearing Gurobi settings in YALMIP:
options = sdpsettings('solver', 'gurobi', 'gurobi.start', []);
-
-
Debug YALMIP Parsing:
- Use YALMIP's diagnostic tools to check the model:
This may highlight inconsistencies in the model.diagnostics = optimize(cons, obj, options); disp(diagnostics);
- Use YALMIP's diagnostic tools to check the model:
-
Update Gurobi Version:
- Ensure you're using the latest compatible version of Gurobi and MATLAB/YALMIP. Sometimes, bugs in specific versions can cause such errors.
-
Test on a Simplified Model:
- Create a minimal example where you only add
E
to the objective function. This can help isolate the problem.
- Create a minimal example where you only add
General Debugging Steps
-
Inspect the Model Size: Check the size of the
model.start
and ensure it matches the total number of decision variables. -
Presolve Settings: Disable Gurobi's presolve as a test:
options = sdpsettings('solver', 'gurobi', 'gurobi.Presolve', 0);
-
Review Variable Definition: Ensure that all variables referenced in
E
are defined before constructing the objective.
- Bot
0 -
Please sign in to leave a comment.
Comments
1 comment