A simple 'for()'
[Example Model: ProductMix5.json]
variables: {
x: {
lower: [0, 0, 0],
finalValue: []
}
},
data: {
profits: {
dimensions: [3],
value: [75, 50, 35],
binding: "get",
finalValue: []
},
parts: {
dimensions: [5, 3],
value: [
[1, 1, 0],
[1, 0, 0],
[2, 2, 1],
[1, 1, 0],
[2, 1, 1]
]
},
inventory: {
value: [450, 250, 800, 450, 600]
}
},
constraints: {
"for(p in 1..5)": {
"cons[p]": { formula: "sumproduct(parts[p,], transpose(x))", upper: 'inventory' }
}
}
In the above example we define 5 constraints in the vertical array cons[]. Cons[] is defined as an array (rather than a table),
by the implicit vertical array upper bound inventory. Each constraint has its own unique index p. To evaluate the first constraint, set p = 1
and compute the formula for that p. (Note: This evaluation is not an array-formula evaluation.) Notice the transposition of x from a vertical matrix
to a horizontal matrix in order to match the horizontal array slice parts[p,].
|