Пример #1
0
        public static void Main(String[] args)
        {
            try {
                cp   = new CP();
                cost = cp.NumExpr();
                List <IIntervalVar> allTasks = new List <IIntervalVar>();
                List <IIntervalVar> joeTasks = new List <IIntervalVar>();
                List <IIntervalVar> jimTasks = new List <IIntervalVar>();

                List <Int32> joeLocations = new List <Int32>();
                List <Int32> jimLocations = new List <Int32>();

                MakeHouse(allTasks, joeTasks, jimTasks, joeLocations, jimLocations, 0, 0, 120, 100.0);
                MakeHouse(allTasks, joeTasks, jimTasks, joeLocations, jimLocations, 1, 0, 212, 100.0);
                MakeHouse(allTasks, joeTasks, jimTasks, joeLocations, jimLocations, 2, 151, 304, 100.0);
                MakeHouse(allTasks, joeTasks, jimTasks, joeLocations, jimLocations, 3, 59, 181, 200.0);
                MakeHouse(allTasks, joeTasks, jimTasks, joeLocations, jimLocations, 4, 243, 425, 100.0);

                ITransitionDistance tt = cp.TransitionDistance(5);
                for (int i = 0; i < 5; ++i)
                {
                    for (int j = 0; j < 5; ++j)
                    {
                        tt.SetValue(i, j, Math.Abs(i - j));
                    }
                }

                IIntervalSequenceVar joe = cp.IntervalSequenceVar(joeTasks.ToArray(), joeLocations.ToArray(), "Joe");
                IIntervalSequenceVar jim = cp.IntervalSequenceVar(jimTasks.ToArray(), jimLocations.ToArray(), "Jim");

                cp.Add(cp.NoOverlap(joe, tt));
                cp.Add(cp.NoOverlap(jim, tt));

                cp.Add(cp.Minimize(cost));


                cp.SetParameter(CP.IntParam.FailLimit, 50000);
                /* EXTRACTING THE MODEL AND SOLVING. */
                if (cp.Solve())
                {
                    for (int i = 0; i < allTasks.Count; ++i)
                    {
                        Console.WriteLine(cp.GetDomain(allTasks[i]));
                    }
                }
                else
                {
                    Console.WriteLine("No solution found.");
                }
            } catch (ILOG.Concert.Exception e) {
                Console.WriteLine(" ERROR: " + e);
            }
        }
Пример #2
0
        public static void Main(String[] args)
        {
            CP cp = new CP();
            List <IIntExpr>     ends     = new List <IIntExpr>();
            List <IIntervalVar> allTasks = new List <IIntervalVar>();
            ITransitionDistance ttime    = cp.TransitionDistance(2);

            ttime.SetValue(dirty, clean, 1);
            workers = cp.CumulFunctionExpr();
            IStateFunction[] houseState = new IStateFunction[nbHouses];
            for (int i = 0; i < nbHouses; i++)
            {
                houseState[i] = cp.StateFunction(ttime);
                MakeHouse(cp, i, ends, allTasks, houseState[i]);
            }
            cp.Add(cp.Le(workers, nbWorkers));
            cp.Add(cp.Minimize(cp.Max(ends.ToArray())));

            /* EXTRACTING THE MODEL AND SOLVING. */
            cp.SetParameter(CP.IntParam.FailLimit, 10000);
            if (cp.Solve())
            {
                for (int i = 0; i < allTasks.Count; i++)
                {
                    Console.WriteLine(cp.GetDomain(allTasks[i]));
                }
                for (int h = 0; h < nbHouses; h++)
                {
                    for (int i = 0; i < cp.GetNumberOfSegments(houseState[h]); i++)
                    {
                        Console.Write("House " + h + " has state ");
                        int s = cp.GetSegmentValue(houseState[h], i);
                        if (s == clean)
                        {
                            Console.Write("Clean");
                        }
                        else if (s == dirty)
                        {
                            Console.Write("Dirty");
                        }
                        else if (s == CP.NoState)
                        {
                            Console.Write("None");
                        }
                        else
                        {
                            Console.Write("Unknown (problem)");
                        }
                        Console.Write(" from ");
                        if (cp.GetSegmentStart(houseState[h], i) == CP.IntervalMin)
                        {
                            Console.Write("Min");
                        }
                        else
                        {
                            Console.Write(cp.GetSegmentStart(houseState[h], i));
                        }
                        Console.Write(" to ");
                        if (cp.GetSegmentEnd(houseState[h], i) == CP.IntervalMax)
                        {
                            Console.WriteLine("Max");
                        }
                        else
                        {
                            Console.WriteLine((cp.GetSegmentEnd(houseState[h], i) - 1));
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No solution found. ");
            }
        }
Пример #3
0
        public static void Main(String[] args)
        {
            try
            {
                CP cp = new CP();

                ITransitionDistance setup1 = cp.TransitionDistance(NbTypes);
                ITransitionDistance setup2 = cp.TransitionDistance(NbTypes);
                int i, j;
                for (i = 0; i < NbTypes; ++i)
                {
                    for (j = 0; j < NbTypes; ++j)
                    {
                        setup1.SetValue(i, j, SetupM1[NbTypes * i + j]);
                        setup2.SetValue(i, j, SetupM2[NbTypes * i + j]);
                    }
                }
                int[]          tp = new int[NbTasks];
                IIntervalVar[] a  = new IIntervalVar[NbTasks];
                IIntervalVar[] a1 = new IIntervalVar[NbTasks];
                IIntervalVar[] a2 = new IIntervalVar[NbTasks];

                String name;
                for (i = 0; i < NbTasks; ++i)
                {
                    int type = TaskType[i];
                    int d    = TaskDur[i];
                    tp[i] = type;
                    name  = "A" + i + "_TP" + type;
                    a[i]  = cp.IntervalVar(d, name);
                    IIntervalVar[] alt = new IIntervalVar[2];
                    name  = "A" + i + "_M1_TP" + type;
                    a1[i] = cp.IntervalVar(name);
                    a1[i].SetOptional();
                    alt[0] = a1[i];
                    name   = "A" + i + "_M2_TP" + type;
                    a2[i]  = cp.IntervalVar(name);
                    a2[i].SetOptional();
                    alt[1] = a2[i];
                    cp.Add(cp.Alternative(a[i], alt));
                }

                IIntervalSequenceVar s1 = cp.IntervalSequenceVar(a1, tp);
                IIntervalSequenceVar s2 = cp.IntervalSequenceVar(a2, tp);
                cp.Add(cp.NoOverlap(s1, setup1, true));
                cp.Add(cp.NoOverlap(s2, setup2, true));

                IIntExpr nbLongSetups = cp.IntExpr();
                for (i = 0; i < NbTasks; ++i)
                {
                    int   tpi          = TaskType[i];
                    int[] isLongSetup1 = new int[NbTypes + 1];
                    int[] isLongSetup2 = new int[NbTypes + 1];
                    for (j = 0; j < NbTypes; ++j)
                    {
                        isLongSetup1[j] = (30 <= SetupM1[NbTypes * tpi + j]) ? 1 : 0;
                        isLongSetup2[j] = (30 <= SetupM2[NbTypes * tpi + j]) ? 1 : 0;
                    }
                    isLongSetup1[NbTypes] = 0; // Last on resource or resource not selected
                    isLongSetup2[NbTypes] = 0; // Last on resource or resource not selected
                    nbLongSetups          = cp.Sum(nbLongSetups,
                                                   cp.Element(isLongSetup1, cp.TypeOfNext(s1, a1[i], NbTypes, NbTypes)));
                    nbLongSetups = cp.Sum(nbLongSetups,
                                          cp.Element(isLongSetup2, cp.TypeOfNext(s2, a2[i], NbTypes, NbTypes)));
                }
                cp.Add(cp.Minimize(nbLongSetups));

                cp.SetParameter(CP.IntParam.FailLimit, 100000);
                cp.SetParameter(CP.IntParam.LogPeriod, 10000);
                if (cp.Solve())
                {
                    Console.WriteLine("Machine 1: ");
                    IIntervalVar x;
                    for (x = cp.GetFirst(s1); !x.Equals(cp.GetLast(s1)); x = cp.GetNext(s1, x))
                    {
                        Console.WriteLine(cp.GetDomain(x));
                    }
                    Console.WriteLine(cp.GetDomain(x));
                    Console.WriteLine("Machine 2: ");
                    for (x = cp.GetFirst(s2); !x.Equals(cp.GetLast(s2)); x = cp.GetNext(s2, x))
                    {
                        Console.WriteLine(cp.GetDomain(x));
                    }
                    Console.WriteLine(cp.GetDomain(x));
                    Console.WriteLine("Number of long transition times \t: " + cp.ObjValue);
                }
                else
                {
                    Console.WriteLine("No solution found.");
                }
            }
            catch (IloException e)
            {
                Console.WriteLine("Error: " + e);
            }
        }
Пример #4
0
        public static void Main(String[] args)
        {
            try
            {
                CP cp = new CP();
                ITransitionDistance setup1 = cp.TransitionDistance(NbTypes);
                ITransitionDistance setup2 = cp.TransitionDistance(NbTypes);
                int i, j;
                for (i = 0; i < NbTypes; ++i)
                {
                    for (j = 0; j < NbTypes; ++j)
                    {
                        int d1 = SetupM1[NbTypes * i + j];
                        if (d1 < 0)
                        {
                            d1 = CP.IntervalMax; // Forbidden transition
                        }
                        setup1.SetValue(i, j, d1);
                        int d2 = SetupM2[NbTypes * i + j];
                        if (d2 < 0)
                        {
                            d2 = CP.IntervalMax; // Forbidden transition
                        }
                        setup2.SetValue(i, j, d2);
                    }
                }
                int[]          tp   = new int[NbTasks];
                IIntervalVar[] a    = new IIntervalVar[NbTasks];
                IIntervalVar[] a1   = new IIntervalVar[NbTasks];
                IIntervalVar[] a2   = new IIntervalVar[NbTasks];
                IIntExpr[]     ends = new IIntExpr[NbTasks];

                String name;
                for (i = 0; i < NbTasks; ++i)
                {
                    int type = TaskType[i];
                    int d1   = TaskDurM1[i];
                    int d2   = TaskDurM2[i];
                    tp[i] = type;
                    name  = "A" + i + "_TP" + type;
                    a[i]  = cp.IntervalVar(name);
                    IIntervalVar[] alt = new IIntervalVar[2];
                    name  = "A" + i + "_M1_TP" + type;
                    a1[i] = cp.IntervalVar(d1, name);
                    a1[i].SetOptional();
                    alt[0] = a1[i];
                    name   = "A" + i + "_M2_TP" + type;
                    a2[i]  = cp.IntervalVar(d2, name);
                    a2[i].SetOptional();
                    alt[1] = a2[i];
                    cp.Add(cp.Alternative(a[i], alt));
                    ends[i] = cp.EndOf(a[i]);
                }

                IIntervalSequenceVar s1 = cp.IntervalSequenceVar(a1, tp);
                IIntervalSequenceVar s2 = cp.IntervalSequenceVar(a2, tp);
                cp.Add(cp.NoOverlap(s1, setup1, true));
                cp.Add(cp.NoOverlap(s2, setup2, true));
                cp.Add(cp.Minimize(cp.Max(ends)));

                cp.SetParameter(CP.IntParam.FailLimit, 100000);
                cp.SetParameter(CP.IntParam.LogPeriod, 10000);
                if (cp.Solve())
                {
                    Console.WriteLine("Machine 1: ");
                    IIntervalVar x;
                    for (x = cp.GetFirst(s1); !x.Equals(cp.GetLast(s1)); x = cp.GetNext(s1, x))
                    {
                        Console.WriteLine(cp.GetDomain(x));
                    }
                    Console.WriteLine(cp.GetDomain(x));
                    Console.WriteLine("Machine 2: ");
                    for (x = cp.GetFirst(s2); !x.Equals(cp.GetLast(s2)); x = cp.GetNext(s2, x))
                    {
                        Console.WriteLine(cp.GetDomain(x));
                    }
                    Console.WriteLine(cp.GetDomain(x));
                    Console.WriteLine("Makespan \t: " + cp.ObjValue);
                }
                else
                {
                    Console.WriteLine("No solution found.");
                }
            }
            catch (IloException e)
            {
                Console.WriteLine("Error: " + e);
            }
        }