Exemple #1
0
        public CustomSumConstraint(String op, String var, CPInstance i)

        {
            varI = var.Trim();
            opI  = op.Trim();


            Variable output = null;

            if (i.variableExists(var))
            {
                isVar  = true;
                output = i.getVarByName(varI);
            }
            else
            {
                isVar = false;
            }

            base.variables = new List <Variable>();

            if (output != null)
            {
                variables.Add(output);
                base.involvedVariables().Add(output);
                output.usedInConstraint(this);
            }

            last_varI  = varI;
            last_opI   = opI;
            last_isVar = isVar;
        }
Exemple #2
0
 internal void drawConstraintsInCell(DataGridViewCellPaintingEventArgs e, CPInstance i)
 {
     foreach (Constraint c in involvedInConstraint)
     {
         CellTools.drawConstraint(this, c, e, i);
     }
 }
Exemple #3
0
        private void load_button_Click(object sender, EventArgs e)
        {
            CPInstance i = SaveLoadTools.load(dataGridView1);

            if (i != null)
            {
                instance = i;
            }
        }
Exemple #4
0
        public void initializeForm(CPInstance instance)
        {
            if (mzinc == null)
            {
                mzinc = new MiniZincInterface();
            }

            this.initializeGrid();

            Form1.instance = instance;

            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;

            stack = new UndoStack();
            refreshUndoButtons();

            lastConstraint = null;
        }
Exemple #5
0
        public static Constraint fromSerialization(string s, CPInstance i)
        {
            AllDifferentConstraint c = new AllDifferentConstraint();

            String[] values = s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            List <Variable> involvedV = new List <Variable>();

            for (int index = 1; index < values.Length; index++)
            {
                Variable v = i.getVarByName(values[index]);
                if (v != null)
                {
                    involvedV.Add(v);
                }
            }

            c.addVariables(involvedV);

            return(c);
        }
Exemple #6
0
        internal static void drawConstraint(Variable variable, Constraint c, DataGridViewCellPaintingEventArgs e, CPInstance i)
        {
            Pen p = new Pen(Color.FromArgb(Math.Max(0, 255 - c.duplication_distance * 10), c.getColor()));

            if (c.duplication_distance == 0)
            {
                p.Width = 4f;
            }
            else
            {
                p.Width = 1.5f + 1.0f / c.duplication_distance;
            }

            Variable[] n = i.getNeighbours(variable, c);


            for (int k = 0; k < 4; k++)
            {
                if (n[k] == null)// && n[(k + 4 - 1) % 4] != null && n[(k + 4 + 1) % 4] != null)
                {
                    CellTools.drawStraight(e, k, p);
                }
            }
        }
Exemple #7
0
 public OptToAction(Variable variable, string value, CPInstance instance)
 {
     this.variable = variable;
     this.value    = value;
     this.instance = instance;
 }
Exemple #8
0
 public CreateVariableAction(List <Variable> vars, CPInstance i)
 {
     this.vars = vars;
     this.i    = i;
 }
Exemple #9
0
 internal static Variable loadVar(CPInstance i, string v)
 {
     String[] data = v.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
     return(i.getVarByName(data[0]));
 }
Exemple #10
0
        internal string solve(CPInstance instance, SolverName solver)
        {
            String instance_path = instance.writeFile();

            result = "";

            gotResult = false;

            List <Solver> solvers       = new List <Solver>();
            List <Thread> solverThreads = new List <Thread>();

            processList = new List <Process>();

            if (solver == SolverName.minizinc || solver == SolverName.all)
            {
                solvers.Add(new FlatZincSolver(instance_path));
            }
            if (solver == SolverName.gecode || solver == SolverName.all)
            {
                solvers.Add(new GecodeSolver(instance_path));
            }
            if (solver == SolverName.or_tools || solver == SolverName.all)
            {
                solvers.Add(new ORToolsSolver(instance_path));
            }
            if (solver == SolverName.chuffed || solver == SolverName.all)
            {
                solvers.Add(new ChuffedSolver(instance_path));
            }



            foreach (Solver s in solvers)
            {
                solverThreads.Add(new Thread(() =>
                {
                    try
                    {
                        result = s.solve();
                        Console.Out.WriteLine("Solver sucessfully finished: " + s);
                        gotResult = true;
                    }
                    catch (Exception e)
                    {
                        Console.Out.WriteLine("Solver crashed: " + s);
                    }
                }));
            }

            WaitingScreen wait = new WaitingScreen(solverThreads);

            wait.ShowDialog();

            var list = new List <Process>(processList);

            foreach (Process process in list)
            {
                try
                {
                    if (!process.HasExited)
                    {
                        Kill(process.Id.ToString());
                    }
                }
                catch (InvalidOperationException e)
                {
                    // do nothing, process already gone
                }
            }


            if (result != "")
            {
                if (result.Contains("UNSATISFIABLE"))
                {
                    instance.unsatisfiable = true;
                    Console.WriteLine("Instance unsatisfiable!");
                }

                return(result);
            }
            else
            {
                return("");
            }
        }