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

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.
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

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2013년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by