0

Let Set B={4,2,8,6,5};

how to write below sets in CPLEX

Set E={p| for all b∈B , p=random integer in range(0,b)}

Set F= {Set of all E} (need multiple sets of E using varying random integers p)

Prarup
  • 7
  • 3

1 Answers1

0
{int} B={4,2,8,6,5};

range r=1..4;

{int} E[i in r]={rand(b) | b in B};

tuple f
{
  {int} s;
}

{f} F={<E[i]> | i in r};

execute
{
  writeln(F);
}

gives

{<{0 2 4}> <{3 1 0 5}> <{0 5 2 3}> <{3 1 6 4}>}

but could give other results (random) ....

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thanks Alex. Why does E[1] have 3 elements only, and the rest of them 4, when Set B has 5 elements? Shouldn't a random number be generated corresponding every element of B. – Prarup May 06 '21 at 17:00
  • 1
    Because the sets in E are sets, not lists or arrays or similar. If the random number generator gives the same number more than once, it doesn't store the repeats. – TimChippingtonDerrick May 06 '21 at 22:09