A simple 'for()' with index set and table assignment
[Example Model: UGProductMixTab4 - To open, click RASON Examples - Example Models discussed in RASON User Guide.]
indexSets : {
part", value: ['chas','tube','cone','psup','elec'] },
{ name: "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: { indexCols: ['part'], value: [['chas',450], ['tube',250],
['cone',800], ['psup',450], ['elec',600]] }
},
constraints: {
"for(p in 'part')": {
"cons[p]": { formula: "sumproduct(parts[p,], x) - inventory[p]",
upper: 0 }
}
}
In this example, five constraints are created; one for each value of p in the index set 'part'. The results are assigned to cons[p]. Within constraints, cons[p] is defined as a table, not an array, because
neither the dimensions property nor the upper, lower, or value properties are used to implicitly define it as an array. Since p belongs to an index set, table elements are referenced by index names (for example,
cons['chas']) rather than numeric positions such as cons[1]). In practice, when defining model functions that use index sets, the formula result identifier will usually be a table.
Note: When a formula result is indexed by an index set, RASON creates a table by default. To create an array instead, you must explicitly define it using the dimensions property or by specifying value, upper,
or lower properties. For example, result[p] where p belongs to an index set produces a table, while result[i] where i is numeric produces an array.
|