示例#1
0
        public void TestProximityConstraint()
        {
            //    var data = Data.ReadXml(dataPath + Erlangen2012_1, "120", "4");
            var data = Data.ReadXml(dataPath + ITC_Comp05, "120", "4");
            // var formulation = ProblemFormulation.UD2;
            //Formulation.AvailabilityHardConstraint = false;
            //Formulation.OverbookingAllowed = 0.35;
            var ModelParameters = new CCTModel.MIPModelParameters()
            {
                UseStageIandII           = false,
                ConstraintPenalty        = 50,
                AbortSolverOnZeroPenalty = true,
            };
            var model = new CCTModel(data, formulation, ModelParameters);
            var watch = Stopwatch.StartNew();

            model.Optimize(30, 0.99);
            var obj = model.ObjSoftCons;

            model.SetObjective(0, 0, 1);

            while (watch.Elapsed.TotalSeconds < TimelimitStageI)
            {
                model.SetProximityOrigin(true);
                model.SetQualConstraint(obj - 10);
                model.Optimize(15);
                obj = model.ObjSoftCons;
                Console.WriteLine($"Objective: {obj}");
            }
        }
示例#2
0
        public QualityRecoveringOptimizer(Data data, Solution solutionBefore, ProblemFormulation formulation, CCTModel.MIPModelParameters mipModelParameters)
        {
            this.data               = data;
            this.formulation        = formulation;
            this.MIPmodelParameters = mipModelParameters;
            this.solutionBefore     = solutionBefore;

            model = new CCTModel(data, formulation, MIPmodelParameters);
            model.SetProximityOrigin(solutionBefore._assignments.ToList());
            model.SetMipHints(solutionBefore._assignments.ToList());
        }
示例#3
0
        public Solution Run()
        {
            var stopwatch = Stopwatch.StartNew();

            var model = new CCTModel(data, formulation, MIPmodelParameters);

            model.Optimize(TimelimitStageI - Timetotighten);
            var userooms = model.GetUsedRooms();

            Console.WriteLine($"Used rooms: {userooms.Sum(kv => kv.Value)} over {userooms.Count} ");
            Console.WriteLine($"OveruseOnTimeslots: {model.GetOverUseOfRooms()} ");

            //  model.PenalizeRoomUsedMoreThanOnce(100);
            model.PenalizeRoomUsedMoreThanOnce(10, true);

            model.SetObjective(0, 0, 0.01);
            //model.SetObjective(0, 0, 0);
            //model.SetMipHintToCurrent();
            model.SetProximityOrigin();
            model.SetQualConstraint(model.ObjSoftCons);

            model.Fixsol(true);
            model.Optimize();
            model.Fixsol(false);

            //    model.Optimize(timetotighten+50,cutoff:500);
            model.ModelParameters.AbortSolverOnZeroPenalty = true;
            var tighttimer = Stopwatch.StartNew();

            model.Optimize(Timetotighten + 300);
            tighttimer.Stop();
            model.DisplayObjectives();
            _solution = new Solution(data, formulation);
            _solution.SetAssignments(model.GetAssignments());

            //timers
            stopwatch.Stop();
            tighttimer.Stop();
            totalseconds     = (int)stopwatch.Elapsed.TotalSeconds;
            roomtightseconds = (int)tighttimer.Elapsed.TotalSeconds;
            return(_solution);
        }
示例#4
0
        public Solution RunUnavailbility()
        {
            var stopwatch = Stopwatch.StartNew();

            var model = new CCTModel(data, formulation, MIPmodelParameters);

            model.Optimize(TimelimitStageI - Timetotighten);
            Console.WriteLine($"Unavailableused: {model.GetUnavailableused()} ({(double) model.GetUnavailableused()/data.Courses.Sum(c => c.Lectures):0.00%})");

            model.PenalizeUnavailability(10);

            // model.SetObjective(0, 0, 0.01);
            // model.SetObjective(0, 0, 0);
            //model.SetMipHintToCurrent();
            model.SetProximityOrigin();
            // model.SetQualConstraint(model.ObjSoftCons);

            model.Fixsol(true);
            model.Optimize();
            model.Fixsol(false);

            //    model.Optimize(timetotighten+50,cutoff:500);
            //     model.ModelParameters.AbortSolverOnZeroPenalty = true;
            var tighttimer = Stopwatch.StartNew();

            model.Optimize(Timetotighten + 900);
            tighttimer.Stop();
            model.DisplayObjectives();
            _solution = new Solution(data, formulation);
            _solution.SetAssignments(model.GetAssignments());

            Console.WriteLine($"Unavailableused: {model.GetUnavailableused()} ({(double)model.GetUnavailableused() / data.Courses.Sum(c => c.Lectures):0.00%})");

            //timers
            stopwatch.Stop();
            tighttimer.Stop();
            totalseconds     = (int)stopwatch.Elapsed.TotalSeconds;
            roomtightseconds = (int)tighttimer.Elapsed.TotalSeconds;

            return(_solution);
        }
示例#5
0
        public void TestLocalBranchingConstraint(bool usecurr, int N)
        {
            var data = Data.ReadXml(dataPath + ITC_Comp05, "120", "4");
            //var formulation = ProblemFormulation.UD2;
            //Formulation.AvailabilityHardConstraint = false;
            //Formulation.OverbookingAllowed = 0.35;
            var modelParameters = new CCTModel.MIPModelParameters()
            {
                UseStageIandII = false
            };
            var model = new CCTModel(data, formulation, modelParameters);

            model.Optimize(30 * 3, 0.99);
            model.SetProxConstraint(N);
            var watch = Stopwatch.StartNew();

            while (watch.Elapsed.TotalSeconds < TimelimitStageI)
            {
                model.SetProximityOrigin(usecurr);
                model.Optimize(15);
            }
        }
示例#6
0
        private void OptimizeSubProblem(int minSoftConsViol, int maxSoftConsViol, double minCost, double maxCost, double alpha)
        {
            StartLogging();

            double?qual   = null;
            double?budget = null;

            if (EpsilonOnQuality)
            {
                qual = Math.Floor(minSoftConsViol * (1 - alpha) + maxSoftConsViol * alpha);
                _model.SetQualConstraint((int?)Math.Floor((double)qual));
                Console.WriteLine($"Alpha: {alpha:0.00} QualConstraint: {qual}");
            }
            else
            {
                budget = minCost * (1 - alpha) + maxCost * alpha;
                _model.SetBudgetConstraint(budget);
                Console.WriteLine($"Alpha: {alpha:0.00} BudgetConstraint: {budget}");
            }

            /*
             * a weighting scheme
             *  model.SetObjective(alpha* minRoomCost, (1-alpha)* minQual);
             */
            if (LocalBranching > 0)
            {
                _model.SetProximityOrigin();
            }

            _model.Optimize(Timelimit, MIPGap);
            Console.WriteLine($"LastSolution:\n(cost,softobj) = {_model.ObjCost} , {_model.ObjSoftCons}");

            int?costBound    = EpsilonOnQuality ?(int?)Math.Ceiling(_model.ObjBound) : null;
            int?softobjBound = !EpsilonOnQuality ? (int?)Math.Ceiling(_model.ObjBound) : null;

            _multiResults.Add(new MultiResult(_model.ObjCost, _model.ObjSoftCons, costBound, softobjBound, _model.GetUsedRooms(),
                                              _model.GetAssignments(), budget, qual, (int)_stopwatch.Elapsed.TotalSeconds));
            AddAllSolutions(_model);
        }
示例#7
0
        //   [TestCase(ITC_Comp05,1)]

        /*
         * [TestCase(ITC_Comp05, 2)]
         * [TestCase(ITC_Comp05, 3)]
         * [TestCase(ITC_Comp05, 4)]
         * [TestCase(ITC_Comp05, 5)]
         * [TestCase(ITC_Comp05, 6)]
         * [TestCase(ITC_Comp05, 7)]
         * [TestCase(ITC_Comp05, 8)]
         * [TestCase(ITC_Comp05, 11)]
         * [TestCase(ITC_Comp05, 12)]
         * [TestCase(ITC_Comp05, 13)]
         * [TestCase(ITC_Comp05, 14)]
         * [TestCase(ITC_Comp05, 15)]
         * [TestCase(ITC_Comp05, 16)]
         * [TestCase(ITC_Comp05, 17)]
         */
        public void CCfirstHeuristic30s(string filename, int seed) //
        {
            //  var seed = 0;
            for (int ia = 1; ia < 5; ia++)
            {
                seed = ia;

                var data = Data.ReadXml(dataPath + filename, "120", "4");
                // var newrooms = CreateRooms(data);
                // data.SetRoomList(newrooms);

                var problemFormulation = ProblemFormulation.UD2NoOverbook;
                problemFormulation.MinimumWorkingDaysWeight = 0;
                //    problemFormulation.CurriculumCompactnessWeight = 0;
                var par = new CCTModel.MIPModelParameters()
                {
                    TuneGurobi            = true,
                    UseStageIandII        = false,
                    UseHallsConditions    = true,
                    UseRoomHallConditions = true,
                    UseRoomsAsTypes       = false,
                    Seed = seed,
                };
                var model = new CCTModel(data, problemFormulation, par);
                model.SetObjective(1, 0, 0);
                model.Optimize(TimelimitStageI);
                model.DisplayObjectives();
                var result = new Dictionary <double, double>();
                //maybe find better proximity that reflects currciulumcompactness better.
                //Check which curriculum that can be moved without introducting penalties.
                model.SetProximityOrigin(true);
                problemFormulation.MinimumWorkingDaysWeight = 5;
                for (var i = 15; i <= 15; i++)
                {
//                model.SetObjective(0, 0, i);
                    model.SetProxConstraint(i);
                    model.AddMinimumWorkingDaysCost();
                    // model.FixCurricula(true);
                    model.Optimize();
                    model.DisplayObjectives();
                    model.SetObjective(1, 0, 0);
                    model.Fixsol(true);
                    model.Optimize();
                    model.Fixsol(false);
                    model.DisplayObjectives();
                    result[i] = model.Objective;
                }

                Console.WriteLine("Results:");
                Console.WriteLine("i;obj");
                foreach (var r in result)
                {
                    Console.WriteLine($"{r.Key};{r.Value}");
                }

                var best = result.Min(r => r.Value);

                File.AppendAllText(@"c:\temp\heuristic.txt", $"{nameof(CCfirstHeuristic30s)};{filename};{best}\n");
                //  model.FixCurricula(false);

                // maybe also save multiple minimum curriculum solutions
            }
        }
        public void Lex_soft_cost_withTimeslot(string filename)
        {
            var algname = nameof(Lex_soft_cost_withTimeslot);
            //  formulation.AvailabilityHardConstraint = false;
            var data     = Data.ReadXml(dataPath + filename, "120", "4");
            var newrooms = CreateRoomsFixedSize(data, 25, 5);

            data.SetRoomList(newrooms);

            var par = new CCTModel.MIPModelParameters()
            {
                UseStageIandII        = false,
                UseHallsConditions    = true,
                UseRoomHallConditions = true,
                TuneGurobi            = false,
                UseRoomsAsTypes       = false,
            };
            var costmodel = new CCTModel(data, ProblemFormulation.MinimizeRoomCost, par);

            costmodel.Optimize();


            data.SetRoomList(costmodel.GetUsedRooms().Where(kv => kv.Value > 0).Select(kv => kv.Key).ToList());


            //var formulation = ProblemFormulation.UD2NoOverbook;
            // formulation.AvailabilityHardConstraint = false;
            //   formulation.OverbookingAllowed = 0.35;
            var ModelParameters = new CCTModel.MIPModelParameters()
            {
                UseStageIandII        = false,
                TuneGurobi            = true,
                UseHallsConditions    = true,
                UseRoomHallConditions = true,
                // UseRoomsAsTypes = true,
                UseRoomsAsTypes          = false,
                RoomBoundForEachTimeSlot = true,
            };
            var model = new CCTModel(data, _problemFormulation, ModelParameters);

            model.Optimize(300);
            var userooms = model.GetUsedRooms();

            Console.WriteLine($"Used rooms: {userooms.Sum(kv => kv.Value)} over {userooms.Count} ");

            // model.PenalizeRoomUsedMoreThanOnce(100);
            model.PenalizeRoomUsedMoreThanOnce(1, true);
            model.SetObjective(0, 0, 0.001);
            model.SetProximityOrigin();
            model.SetQualConstraint(model.ObjSoftCons);
            // model.SetProxConstraint(20);
            model.Fixsol(true);
            model.Optimize();
            model.Fixsol(false);


            model.Optimize(900);
            model.DisplayObjectives();
            var sol = new Solution(data, ProblemFormulation.MinimizeRoomCost);

            sol.SetAssignments(model.GetAssignments());
            Console.WriteLine(sol.AnalyzeSolution());

            File.AppendAllText(@"c:\temp\heuristic.txt", $"{algname};{filename};{model.ObjSoftCons}\n");
        }