/// <summary> /// Writes the specified data set as the specified target table. /// </summary> /// <param name="name">The name of the OPL data set</param> /// <param name="targetTable">The target table</param> public void WriteTable(DbConnection con, string name, String targetTable) { // The opl element to write OplElement element = this.Model.GetElement(name); ITupleSet tupleSet = element.AsTupleSet(); ITupleSchema tupleSchema = tupleSet.Schema; // drop existing table DropTable(con, targetTable); // Create table String[] tableDef = TableDefinitionFromOplTupleSchema(tupleSchema, true); CreateTable(con, tableDef, targetTable); // Populate table String insertCommand = CreateInsertCommand(tupleSchema, targetTable); foreach (ITuple t in tupleSet) { InsertIntoTable(con, tupleSchema, t, insertCommand); } }
// The purpose of this sample is to check the result of filtering by iterating on the generated data element. // // The data element is an array of strings that is indexed by a set of strings. // It is filled as the result of an iteration on a set of tuples that filters out the duplicates. // It is based on the model used in "Sparsity" run configuration of the "transp" example. // // // The simplified model is: // // {string} Products = ...; // tuple Route { string p; string o; string d; } // {Route} Routes = ...; // {string} orig[p in Products] = { o | <p,o,d> in Routes }; // static int sample1() { int status = 127; const string DATADIR = "../.."; OplFactory.DebugMode = true; OplFactory oplF = new OplFactory(); try { OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out); OplRunConfiguration rc = oplF.CreateOplRunConfiguration(DATADIR + "/transp2.mod", DATADIR + "/transp2.dat"); OplModel opl = rc.GetOplModel(); opl.Generate(); Console.Out.WriteLine("Verification of the computation of orig: "); // Get the orig, Routes, Product elements from the OplModel. ISymbolSetMap orig = opl.GetElement("Orig").AsSymbolSetMap(); ITupleSet Routes = opl.GetElement("Routes").AsTupleSet(); ISymbolSet Products = opl.GetElement("Products").AsSymbolSet(); Console.Out.Write("Products = "); for (int j = 0; j <= Products.Size - 1; j++) { Console.Out.Write(Products.GetValue(j) + " "); } Console.Out.WriteLine(); // Iterate through the orig to see the result of the data element filtering. IEnumerator it1 = Products.GetEnumerator(); while (it1.MoveNext()) { string p = ((string)it1.Current); // This is the last dimension of the array (as it is a one-dimensional array), so you can use the get method directly. Console.Out.WriteLine("for p = " + p + " we have " + orig.Get(p)); } Console.Out.WriteLine("---------------------"); // Iterate through the TupleSet. IEnumerator it2 = Routes.GetEnumerator(); while (it2.MoveNext()) { ITuple t = ((ITuple)it2.Current); // Get the string "p" from the tuple. string p = t.GetStringValue("p"); // if "p" is in the indexer, we will try to add the "o" string to the array. if (Products.Contains(p)) { Console.Out.WriteLine("for p = " + p + " we will have " + t.GetStringValue("o") + " from " + t); } } Console.Out.WriteLine("---------------------"); status = 0; } catch (ILOG.OPL.OplException ex) { Console.WriteLine(ex.Message); status = 2; } catch (ILOG.Concert.Exception ex) { Console.WriteLine(ex.Message); status = 3; } catch (System.Exception ex) { Console.WriteLine(ex.Message); status = 4; } oplF.End(); return(status); }