A simple 'for()'
[Example Model: ProductMix5 -- To open, click RASON Examples - Example Models using Arrays Loops and Tables -- Using Loop]
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 example above, five constraints are created in the vertical array cons[]. The constraints are defined as an array (rather than a table) because 'inventory', holding the upper bounds of the constraints, is a
vertical array. Each constraint has a unique index p. To evaluate a given constraint, the model fixes p to a single value (for example, p = 1) and evaluates the formula for that index. Each constraint is evaluated
independently for a fixed value of p, not as a vectorized array-formula evaluation. Note that 'x' is transposed from a vertical array to a horizontal array so it can be multiplied with the with the row of the parts
array corresponding to index p (parts[p,]).
|