0

I am trying to use Koert Kuipers' matlab code for branch and bound: BNB20. I keep getting

' Error using mofitness (line 4)
Not enough input arguments.'

'Error in bnbmo (line 37)
[errmsg,Z,X,t,c,fail]=...'

Here is the main script with the mofitness function below the main code:

%% GAMULTIOBJ with integer constraints
%
% BRANCH-AND-BOUND BMB20
%% Data import
workbookFile = 'Book1.xlsx';
sheetName = 'Aeq';
range = 'B4:WC111';
Aeqdata = Aeqimport(workbookFile, sheetName, range);
beqsheet = 'beq';
startRow = 1;
endRow = 108;
beqdata = beqimport(workbookFile, beqsheet,startRow, endRow); 

%% Problem setup
P1 = 2; % the weight applied to hard constraints
P2 = 0.2; % the weight applied to soft constraints
fun = @mofitness;  % Function handle to the fitness function
numberOfVariables = 600;   % Number of decision variables

x0 = zeros(600,1);
xstatus(1:600) = 1; % 0 for continuous, 1 for integer, 2 for fixed

% Constraints
A = [];
B = [];
Aeq = Aeqdata;
Beq = beqdata;

nonlcon = @nonlconmo;

% Bound Constraints
xlb = zeros(1,numberOfVariables);       % Lower bound
xub = ones(1,numberOfVariables);         % Upper bound

%% Solve the problem with integer constraints
[errmsg,Z,X,t,c,fail]=...
    BNB20(fun,x0,xstatus,xlb,xub,A,B,Aeq,Beq,nonlcon,0,[],P2,P1)

function mofitness:

function mo = mofitness(x,P2,P1);
P2 = 0.2;
P1 = 2;
mo = P2*(sum(x(11:10:521)) -P1) + P2*(sum(x(12:10:522)) -P1)+ P2*(sum(x(13:10:523)) -P1)...
+ P2*(sum(x(14:10:524)) -P1)+ P2*(sum(x(15:10:525)) -P1)+ P2*(sum(x(16:10:526)) -P1)...
+ P2*(sum(x(17:10:527)) -P1)+ P2*(sum(x(18:10:528)) -P1)+ P2*(sum(x(19:10:529)) -P1)...
+ P2*(sum(x(20:10:530)) -P1);
end

Hope someone can help me, thanks.

Moni
  • 93
  • 1
  • 14
  • 2
    I'm not sure how much clearer "`fun` must be a string" could get: `fun = 'mofitness';`. – TroyHaskin Mar 08 '16 at 02:22
  • Thanks Troy, so I realize that's not the error then. If I leave the function handle out it still understands that mofitness is a defined function. So the real error is 'not enough input arguments'. – Moni Mar 09 '16 at 04:36
  • Simply removing the `@` calls the function with zero arguments. You need to make `fun` a string per my first comment. – TroyHaskin Mar 09 '16 at 18:24
  • Thanks @TroyHaskin but if I use `fun = 'mofitness'` I get the same error: `errmsg = fun must be a string.` – Moni Mar 10 '16 at 02:24
  • `nonlcon` must also be a string. – TroyHaskin Mar 10 '16 at 05:27

0 Answers0