MATLAB: Optimization strange error with linprog

erroroptimizationOptimization Toolbox

I am getting a strange error with the linprog solver:
"Error in farmer (line 28)
[x,obj,exitflag,output,lambda] = check(prob,c,f,A,B,D,b,d);"
There are some warning messages messages appearing on lines 28 and 29 on each output variables of farmer.m file:
"The value assigned here to ____ appears to be unused. Consider replacing it by ~"
I have attached the code. Can anyone please help me to fix the code?

Best Answer

  • benders line 66:
    told_cut_l = cut_left;
    cut_left = [old_cut_l;G alpha;];
    You assign to a variable told_cut_l but you never use that variable anywhere in the file. Meanwhile in the very next line you use old_cut_l . In the absence of comments otherwise, any reader is likely to believe that the assignment should have been to old_cut_l instead of to told_cut_l .
    check line 19:
    opts = optimoptions(@linprog , 'Algorithm','dual - simplex');
    The name of the algorithm has to be 'dual-simplex' with no spaces. You have the same problem in line 10 of benders .
    [x,obj,exitflag,output,lambda] = check(prob,c,f,A,B,D,b,d);
    [x_benders,obj_benders,exitflag_benders,output_benders] =...
    counter = output_benders.iterations;
    LBs = output_benders.LB; UBs = output_benders.UB;
    You assign to x, obj, exitflag, output, lambda, x_benders, obj_benders, exitflag_benders, but you do not use them anywhere. The only variable you use that are output from check() or benders() is output_benders, which you extract three values from. But then you do not do anything with the three values you extract.
    function farmer ()
    You do not return any variables from the function you are inside, so at the end of executing farmer(), all of the variables are going to disappear. The warning messages are pointing out that it is odd to create a variable but then not use it, suggesting either that you made a spelling mistake (like you did for old_cut_l) or else that you forgot to put in code that uses the variables, or else that perhaps you could remove code.
    If you have an assignment to a variable but you never use the variable, then in most cases that means you could remove the assignment without affecting the output. When you call a function but ignore its output, then it has no effect on the final output, not unless it has "side effects" of changing variables not mentioned in the call (such as global variables), or creates graphics, or changes the state of a file (e.g., it might have read further into a file) -- or it takes up time in a system in which time is a consideration.
    If the call is not changing variables in the background, and not creating graphics, and not affecting devices like files, and not dumping information to the display, and not taking up time in a way that matters... then removing the call will not change the outcome of the program (assuming that the call does not cause an error.) And if that doesn't sound appropriate then you should probably be doing something with the variables you assign the results to.