public override void doAction() { foreach (Variable v in selectedVars) { v.usedInConstraint(c); } i.addConstraint(c); }
public static CPInstance load(DataGridView grid) { OpenFileDialog file = new OpenFileDialog(); if (file.ShowDialog() == DialogResult.OK) { String[] data = System.IO.File.ReadAllLines(file.FileName); int index = 2; CPInstance i = new CPInstance(200, 200); // Vars while (index < data.Length && !data[index].StartsWith("--CONSTRAINTS--")) { i.addVariable(Variable.loadVar(data[index], grid)); index++; } index++; // Constraints while (index < data.Length && !data[index].StartsWith("--OPTIMIZATION GOALS--")) { try { String[] values = data[index].Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); Type elementType = Type.GetType(values[0]); MethodInfo f = elementType.GetMethod("fromSerialization"); Constraint c = (Constraint)f.Invoke(null, new Object[] { data[index], i }); if (c != null) { i.addConstraint(c); } } catch (Exception e) { throw e; } index++; } index++; // Opt Goals while (index < data.Length) { Variable v = OptimizationGoal.loadVar(i, data[index]); String value = OptimizationGoal.loadValue(data[index]); i.setOptTo(v, value); index++; } return(i); } return(null); }