2
$\begingroup$

I am sitting on an MultiAgent optimization problem trying to solve for a quadruple of variables

{e,l,b,c}

In a single agent (n=1) environment the optimization problem looks like this which works:

Objective Function:

f[e_?NumericQ, l_?NumericQ, b_?NumericQ] := (l*1.04 + e*1.057 - b*0.8632^(-1))/(-1)

Maximization:

NMaximize[{f[e, l, b], 
  c >= 0.2*d[[1]] && (c + e + l - d[[1]] - b)/(e + 0.2*l) >= 0.09 && 
   c + l + e == b + W[[1]] + d[[1]] && c >= 0 && e >= 0 && l >= 0 &&
    b >= 0}, {e, l, b, c}]

Where d[[1]] and W[[1]] are Values drawn from NormalDistributions:

W = RandomVariate[NormalDistribution[65, 10], {n, 1}]

d = RandomVariate[NormalDistribution[300, 100], {n, 1}]

Output:

{-0.00165118, {e -> 532.54, l -> 626.225, b -> 702.162, c -> 54.2522}}

Problem:

Now I want to expand that problem to a MulitAgent problem, let's say n=10. I don't know how to designate Vector properties to the variables and how to index them properly.

I tried this after clearing all variables:

Objective Function multiple Agents

F[e_?VectorQ, l_?VectorQ, b_?VectorQ] := (l*1.04 + e*1.057 - b*0.8632^(-1))/(-1);

Maximization Multiple Agents

Table[NMaximize[{f[e[[i]], l[[i]], b[[i]], c[[i]]],
  c[[i]] >= 0.2*d[[i]] && (c[[i]] + e[[i]] + l[[i]] - d[[i]] - b[[i]])/(e[[i]] + 0.2*l[[i]]) >= 0.09 && 
   c[[i]] + l[[i]] + e[[i]] == b[[i]] + W[[i]] + d[[i]] && c[[i]] >= 0 && e[[i]] >= 0 && l[[i]] >= 0 &&
    b[[i]] >= 0}, {e[[i]], l[[i]], b[[i]], c[[i]]}],{i,1,n}]

Which is basically the same Maximization as above, only trying to index it, since i hoped that Mathematica would calculate Variables {e[[i]], l[[i]], b[[i]], c[[i]]}, which is for every Agent i different due to drawings of W and d out of the Normal Distribution.

However, the indexation is not proper according to the error message:

Part::partd: "Part specification e[[1]] is longer than depth of object" etc.

How can I transform this scenario in a multiple Vector Scenario?

$\endgroup$
  • $\begingroup$ Creating a Table won't help you. You need to create arrays for your individual variables like eVars = Array[e,n] where n is some fixed integer. Then you need to create an appropriate objective function, that mixes all the components together in the way you want them to interact and yield a real value, not some kind of vector. Essentially you can just optimize in ordered spaces (you need to know whats bigger and smaller). $\endgroup$ – Wizard Jun 23 '15 at 18:30
  • $\begingroup$ Thanks! It worked to define the variable as arrays to create the necessary depth. The Error Message Part::partd: is no problem anymore $\endgroup$ – ResidentStiefel Jun 23 '15 at 21:38
  • 1
    $\begingroup$ ResidentStiefel or @Wizard would either one of you consider writing this solution up as an answer, so the question does not show up as unanswered anymore? Self-answers are also encouraged on StackExchange. $\endgroup$ – MarcoB Jun 25 '15 at 3:52
1
$\begingroup$

Creating a Table won't help you. You need to create an array (list) for your individual variables like

eVars = Array[e,n]

where n is some fixed integer.

Then you need to create an appropriate objective function, that mixes all the components together in the way you want them to interact and yield a real value, not some kind of vector.

From a mathematical standpoint: Essentially you can just optimize in ordered spaces (you need to know whats bigger and smaller).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.