What is wrong with my objective function, called by bintprog?
Show older comments
Hello!
I am solving an optimization problem with 8 variables (x1,...,x8) and each variable has specific benefit and cost. I have to maximize the benefit with the condition that the cost do not exceed the certain value. There is also a condition that if x2 is 1 then x8 also has to be 1, otherwise they are both 0.
My objective function is:
function f = benefit(x)
if ~xor(x(2),x(8)) == 1
f = [-950 -780 -440 -215 -630 -490 -560 -600];
else
f = [100 100 100 100 100 100 100 100]; %extremely non-beneficial
end
This produces the error:
Error using benefit (line 3). Not enough input arguments.
I have no idea what is wrong.
Regards, Anze
Answers (2)
Matt J
on 11 Sep 2013
0 votes
Error using benefit (line 3). Not enough input arguments.
You haven't shown your call to BINTPROG, so we cannot diagnose the error.
Independently of that, though, bintprog does not maximize arbitrary objective functions. The objective function has to be a linear function dot(f,x). In other words, f has to be a vector independent of x.
4 Comments
Matt J
on 11 Sep 2013
Anze Commented:
My call to bintprog is
bintprog(benefit,[400 350 200 100 300 250 300 350],1000)
the second argument is the vector of costs and the third argument is the cost limit.
Anze
on 11 Sep 2013
I think the following might be what you want. The main point is that the "f" input must be a fixed vector.
f=[-950 -780 -440 -215 -630 -490 -560 -600];
A=[400 350 200 100 300 250 300 350];
b=1000;
Aeq=[0 1 0 0 0 0 0 -1]; %equivalent to xor(x(2),x(8)) == 0
beq=0;
bintprog(f,A,b,Aeq,beq);
Alan Weiss
on 11 Sep 2013
0 votes
Please take a look at the documentation and some examples for bintprog. bintprog takes a single vector as an objective function, not a program.
Alan Weiss
MATLAB mathematical toolbox documentation
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!