1: using System; 2: using System.Text; 3: using System.IO; 4: using Aimms; 5: using System.Diagnostics; 6: 7: namespace example 8: { 9: // This example demonstrates some easily made mistakes using the SDK. 10: class Pitfalls 11: { 12: 13: ISession m_Session; 14: 15: public Pitfalls(ISession session) 16: { 17: m_Session = session; 18: } 19: 20: 21: ///<summary> Using set ordering. 22: /// The SDK uses only the 'natural' Aimms ordering, which is the creation order of the labels. 23: /// See also the section on "Set element ordering" in the Execution Efficiency Cookbook chapter in the Aimms Language Reference. 24: /// </summary> 25: public void useOrdinals() 26: { 27: ISetData setCustomers = m_Session.openSet("Customers"); 28: setCustomers.add("Oslo"); 29: setCustomers.add("Madrid"); 30: 31: // If the root set was completely empty until now, the order will be as expected. 32: ISetIterator itCustomers = setCustomers.createIterator(); 33: itCustomers.next(); 34: Debug.Assert("Oslo" == itCustomers.element.Label); 35: itCustomers.next(); 36: Debug.Assert("Madrid" == itCustomers.element.Label); 37: 38: 39: ISetData setDepots = m_Session.openSet("Depots"); 40: setDepots.add("London"); 41: setDepots.add("Oslo"); 42: 43: // Since Depots and Customers share a rootset (Locations), 44: // "Oslo" was added to the rootset before "London". 45: // It will be the first Depot! 46: ISetIterator itDepots = setDepots.createIterator(); 47: itDepots.next(); 48: Debug.Assert("Oslo" == itDepots.element.Label); 49: itDepots.next(); 50: Debug.Assert("London" == itDepots.element.Label); 51: } 52: 53: ///<summary> 54: /// Writing sets. 55: /// Set write actions are recursive: 56: /// - adding a label to a subset will also add it to the superset 57: /// - deleting a label from a set will also delete it from its subsets, 58: /// - emptying a set will empty all its subsets. 59: /// - setLabels() has an implicit empty, therefore setLabels empties all the subsets 60: ///</summary> 61: public void initializeSets() 62: { 63: // the data: 64: String[] locations = { "London", "Oslo", "Madrid" }; 65: String[] customers = { "Oslo", "Madrid" }; 66: String[] depots = { "London", "Oslo" }; 67: 68: // adding the data incorrectly: 69: { 70: ISetData setCustomers = m_Session.openSet("Customers"); 71: setCustomers.setLabels(customers); // This will also add Oslo and Madrid to the superset Locations. 72: ISetData setDepots = m_Session.openSet("Depots"); 73: setDepots.setLabels(depots); // This will also add London to the superset Locations, the others were already present. 74: ISetData setLocations = m_Session.openSet("Locations"); 75: setLocations.setLabels(locations); // This will empty the set and its subsets, and then adds London and Oslo to only itself. 76: 77: Debug.Assert(setDepots.Cardinality == 0); // Probably not intended. 78: } 79: } 80: 81: 82: 83: } 84: }