What is wrong with my objective function, called by bintprog?

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

回答 (2 件)

Matt J
Matt J 2013 年 9 月 11 日

0 投票

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 件のコメント

Matt J
Matt J 2013 年 9 月 11 日
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.
Matt J
Matt J 2013 年 9 月 11 日
編集済み: Matt J 2013 年 9 月 11 日
Again, the first argument, "benefit", isn't allowed to be the name of a function. It has to be a constant vector of weights.
Anze
Anze 2013 年 9 月 11 日
So it is not possible to take the second condition into account with bintprog?
Matt J
Matt J 2013 年 9 月 11 日
編集済み: Matt J 2013 年 9 月 11 日
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
Alan Weiss 2013 年 9 月 11 日

0 投票

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

カテゴリ

質問済み:

2013 年 9 月 11 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by