A simple 'for()' with index set and array assignment
[Example Model: ProductMixTab3.json]
indexSets : {
part: { value: ['chas','tube','cone','psup','elec'] },
prod: { value: ['tv','stereo','speaker'] }
],
data : {
parts : { indexCols: ['part', 'prod'],
value: [['chas', 'tv', 1],
['elec', 'stereo', 1],
['tube', 'tv', 1],
['cone', 'tv', 2],
['cone', 'stereo', 2],
['chas', 'stereo', 1],
['cone', 'speaker', 1],
['psup', 'tv', 1],
['psup', 'stereo', 1],
['elec', 'tv', 2],
['elec', 'speaker', 1]]
},
inventory: { dimensions: ['part'], value: [450, 250, 800, 450, 600] }
},
constraints: {
"for(p in 'part')": {
"cons[p]": { formula: "sumproduct(parts[p,], x)", upper: 'inventory' }
}
}
In the above example we again define 5 constraints in the vertical array cons[]. As in the example above, cons[] is defined as an array (rather than a table), by the implicit vertical array upper bound inventory. However, this time the index p belongs to an index set. Notice that x is not transposed here. This is because parts is a table, where slice parts[p,] is always a vertical array.
|