public Decision Build( IIntMap<int> outcomeArrows, IntInterval possibleBounds, IIntFrequency frequency) { defaultAction = outcomeArrows.DefaultValue; this.actionIdToDecision[defaultAction] = new ActionDecision(defaultAction); Decision result; if (TryBuildElementaryTree(outcomeArrows, out result)) { return result; } // TODO: Alternatively to averaging probability, each test can // be split if probability varies significantly within test range DecisionTest[] tests = outcomeArrows .EnumerateCoverage(possibleBounds) .Select( a => new DecisionTest(a.Key, a.Value, frequency.Average(a.Key)) ) .ToArray(); result = GenTree(new ArraySlice<DecisionTest>(tests)); return result; }
public Decision Build( IIntMap <int> outcomeArrows, IntInterval possibleBounds, IIntFrequency frequency) { defaultAction = outcomeArrows.DefaultValue; this.actionIdToDecision[defaultAction] = new ActionDecision(defaultAction); Decision result; if (TryBuildElementaryTree(outcomeArrows, out result)) { return(result); } // TODO: Alternatively to averaging probability, each test can // be split if probability varies significantly within test range DecisionTest[] tests = outcomeArrows .EnumerateCoverage(possibleBounds) .Select( a => new DecisionTest(a.Key, a.Value, frequency.Average(a.Key)) ) .ToArray(); result = GenTree(new ArraySlice <DecisionTest>(tests)); return(result); }
public static SwitchGenerator Sparse( IIntMap<int> arrows, IntInterval possibleBounds, IIntFrequency frequency = null) { var result = new SparseSwitchGenerator(arrows, possibleBounds, frequency); return result; }
public static SwitchGenerator Sparse( IIntMap <int> arrows, IntInterval possibleBounds, IIntFrequency frequency = null) { var result = new SparseSwitchGenerator(arrows, possibleBounds, frequency); return(result); }
// The purpose of this sample is to output a multidimensional array x[i][j] to illustrate how arrays and subarrays are managed. // To access the elements of an array, you must first access the subarrays up to the last dimension, then you can get the values. // Here, as there are two dimensions, you have to get one subarray from which you can directly get the values. // // The array of integers is indexed by two sets of strings.. // // The simplified model is: // // {string} s1 = ...; // {string} s2 = ...; // {int} x[s1][s2] = ...; // static int sample2() { 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 + "/iterators.mod"); OplModel opl = rc.GetOplModel(); opl.Generate(); // Get the x, s1 and s2 elements from the OplModel. IIntMap x = opl.GetElement("x").AsIntMap(); ISymbolSet s1 = opl.GetElement("s1").AsSymbolSet(); ISymbolSet s2 = opl.GetElement("s2").AsSymbolSet(); // Iterate on the first indexer. IEnumerator it1 = s1.GetEnumerator(); while (it1.MoveNext()) { // Get the second dimension array from the first dimension. IIntMap sub = x.GetSub((string)it1.Current); // Iterate on the second indexer of x (that is the indexer of the subarray). IEnumerator it2 = s2.GetEnumerator(); while (it2.MoveNext()) { // This is the last dimension of the array, so you can directly use the get method. Console.Out.WriteLine(it1.Current + " " + it2.Current + " " + sub.Get((string)it2.Current)); } } Console.Out.WriteLine("---------------------"); status = 0; } catch (ILOG.OPL.OplException ex) { Console.WriteLine(ex.Message); status = 1; } catch (IloException ex) { Console.Out.WriteLine("### exception: " + ex.Message); status = 2; } catch (System.Exception ex) { Console.Out.WriteLine("### UNEXPECTED ERROR ..." + ex.Message); status = 3; } oplF.End(); return(status); }
public SparseSwitchGenerator( IIntMap<int> intMap, IntInterval possibleBounds, IIntFrequency frequency) { this.strategy = new InlineFirstDTStrategy(this); this.intMap = intMap; this.possibleBounds = possibleBounds; this.frequency = frequency ?? new UniformIntFrequency(possibleBounds); }
public SparseSwitchGenerator( IIntMap <int> intMap, IntInterval possibleBounds, IIntFrequency frequency) { this.strategy = new InlineFirstDTStrategy(this); this.intMap = intMap; this.possibleBounds = possibleBounds; this.frequency = frequency ?? new UniformIntFrequency(possibleBounds); }
private bool TryBuildElementaryTree(IIntMap <int> map, out Decision result) { result = null; int count = 0; foreach (var arrow in map.Enumerate()) { if (arrow.Value == map.DefaultValue) { continue; } ++count; if (count > platform.MaxLinearCount || arrow.Key.LongSize != 1) { return(false); } } RelationalBranchDecision lastParent = null; foreach (var arrow in map.Enumerate()) { if (arrow.Value == map.DefaultValue) { continue; } var node = new RelationalBranchDecision(RelationalOperator.Equal, arrow.Key.First); node.Left = GetActionDecision(arrow.Value); if (lastParent == null) { result = node; } else { lastParent.Right = node; } lastParent = node; } lastParent.Right = DefaultActionDecision; return(true); }
public SparseSwitchGenerator(IIntMap<int> intMap, IntInterval possibleBounds) : this(intMap, possibleBounds, null) { }
static int Main(string[] args) { int status = 127; const string DATADIR = "../.."; const double RC_EPS = 0.000001; try { OplFactory.DebugMode = true; OplFactory oplF = new OplFactory(); OplErrorHandler errHandler = oplF.CreateOplErrorHandler(); OplSettings settings = oplF.CreateOplSettings(errHandler); // Make master model Cplex masterCplex = oplF.CreateCplex(); masterCplex.SetOut(null); OplRunConfiguration masterRC0 = oplF.CreateOplRunConfiguration(DATADIR + "/cutstock.mod", DATADIR + "/cutstock.dat"); masterRC0.Cplex = masterCplex; OplDataElements masterDataElements = masterRC0.OplModel.MakeDataElements(); // prepare sub model source, definition and engine OplModelSource subSource = oplF.CreateOplModelSource(DATADIR + "/cutstock-sub.mod"); OplModelDefinition subDef = oplF.CreateOplModelDefinition(subSource, settings); Cplex subCplex = oplF.CreateCplex(); subCplex.SetOut(null); const int nbItems = 5; IIntRange items = masterCplex.IntRange(1, 5); double best; double curr = double.MaxValue; do { best = curr; masterCplex.ClearModel(); OplRunConfiguration masterRC = oplF.CreateOplRunConfiguration(masterRC0.OplModel.ModelDefinition, masterDataElements); masterRC.Cplex = masterCplex; masterRC.OplModel.Generate(); Console.Out.WriteLine("Solve master."); if (masterCplex.Solve()) { curr = masterCplex.ObjValue; Console.Out.WriteLine("OBJECTIVE: " + curr); status = 0; } else { Console.Out.WriteLine("No solution!"); status = 1; } // prepare sub model data OplDataElements subDataElements = oplF.CreateOplDataElements(); subDataElements.AddElement(masterDataElements.GetElement("RollWidth")); subDataElements.AddElement(masterDataElements.GetElement("Size")); subDataElements.AddElement(masterDataElements.GetElement("Duals")); // get reduced costs and set them in sub problem INumMap duals = subDataElements.GetElement("Duals").AsNumMap(); for (int i = 1; i <= nbItems; i++) { IForAllRange forAll = (IForAllRange)masterRC.OplModel.GetElement("ctFill").AsConstraintMap().Get(i); duals.Set(i, masterCplex.GetDual(forAll)); } //make sub model OplModel subOpl = oplF.CreateOplModel(subDef, subCplex); subOpl.AddDataSource(subDataElements); subOpl.Generate(); Console.Out.WriteLine("Solve sub."); if (subCplex.Solve()) { Console.Out.WriteLine("OBJECTIVE: " + subCplex.ObjValue); status = 0; } else { Console.Out.WriteLine("No solution!"); status = 1; } if (subCplex.ObjValue > -RC_EPS) { break; } // Add variable in master model IIntMap newFill = masterCplex.IntMap(items); for (int i = 1; i <= nbItems; i++) { int coef = (int)subCplex.GetValue(subOpl.GetElement("Use").AsIntVarMap().Get(i)); newFill.Set(i, coef); } ITupleBuffer buf = masterDataElements.GetElement("Patterns").AsTupleSet().MakeTupleBuffer(-1); buf.SetIntValue("id", masterDataElements.GetElement("Patterns").AsTupleSet().Size); buf.SetIntValue("cost", 1); buf.SetIntMapValue("fill", newFill); buf.Commit(); subOpl.End(); masterRC.End(); } while (best != curr && status == 0); oplF.End(); } 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; } Console.WriteLine("--Press <Enter> to exit--"); Console.ReadLine(); return(status); }
public SparseSwitchGenerator(IIntMap <int> intMap, IntInterval possibleBounds) : this(intMap, possibleBounds, null) { }
private bool TryBuildElementaryTree(IIntMap<int> map, out Decision result) { result = null; int count = 0; foreach (var arrow in map.Enumerate()) { if (arrow.Value == map.DefaultValue) { continue; } ++count; if (count > platform.MaxLinearCount || arrow.Key.LongSize != 1) { return false; } } RelationalBranchDecision lastParent = null; foreach (var arrow in map.Enumerate()) { if (arrow.Value == map.DefaultValue) { continue; } var node = new RelationalBranchDecision(RelationalOperator.Equal, arrow.Key.First); node.Left = GetActionDecision(arrow.Value); if (lastParent == null) { result = node; } else { lastParent.Right = node; } lastParent = node; } lastParent.Right = DefaultActionDecision; return true; }