コード例 #1
0
        private void RunWieghtedSumMetod(int minSoftConsViol, int maxSoftConsViol, double minCost, double maxCost)
        {
            List <MultiResult> pareto;

            var queue = new Queue <Tuple <int, int, int, int> >();

            queue.Enqueue(Tuple.Create(minSoftConsViol, maxSoftConsViol, (int)minCost, (int)maxCost));
            for (int i = 0; i < Steps; i++)
            {
                if (queue.Count == 0)
                {
                    Console.WriteLine("Queue empty.. breaking");
                    break;
                }
                var point = queue.Dequeue();
                Console.WriteLine($"Point: {point}");

                var softconstweight = point.Item4 - point.Item3;
                var costweight      = point.Item2 - point.Item1;

                if (costweight < 0.1 || softconstweight < 0.1)
                {
                    Console.WriteLine("no slope.. skipping");
                    continue;
                }

                _model.SetObjective(softconstweight, costweight);

                Console.WriteLine($"Slope set to: {(double) softconstweight/costweight : #.##}");
                var solfound = _model.Optimize(Timelimit, MIPGap);
                Console.WriteLine($"LastSolution:\n(cost,softobj) = {_model.ObjCost} , {_model.ObjSoftCons}");
                if (solfound)
                {
                    queue.Enqueue(Tuple.Create(point.Item1, _model.ObjSoftCons, (int)_model.ObjCost, point.Item4));
                    queue.Enqueue(Tuple.Create(_model.ObjSoftCons, point.Item2, point.Item3, (int)_model.ObjCost));
                    // Maybe remove dominated solutions.
                    // _model.ObjBound <= cost*costweight + softobj*softobjweigh
                    var costBound    = (int)Math.Floor(_model.ObjBound / costweight);
                    var softobjBound = (int)Math.Floor(_model.ObjBound / softconstweight);

                    _multiResults.Add(new MultiResult(_model.ObjCost, _model.ObjSoftCons, costBound, softobjBound,
                                                      _model.GetUsedRooms(),
                                                      _model.GetAssignments(), null, null, (int)_stopwatch.Elapsed.TotalSeconds));
                }
                AddAllSolutions(_model);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: DataAnalysis.cs プロジェクト: lulzzz/UniTimetabling
        public void MaximizeRoomUtilization(string filename)
        {
            var data = Data.ReadXml(dataPath + filename, "120", "4");

            Console.WriteLine($"Dataset: {data.Name}");
            Console.WriteLine($"Courses: {data.Courses.Count} Lectures: {data.Courses.Sum(c => c.Lectures)}");



            //DisplayRoomStats("original",data.Rooms.ToDictionary(r => r, r => 1), data);

            //  var newrooms = CreateRooms(data);
            var newrooms = CreateRoomsFixedSize(data, 25, 1);

            data.SetRoomList(newrooms);


            Console.WriteLine("\nLectures:\n");
            Console.WriteLine("size,hours");

            foreach (var coursesizes in data.Courses.GroupBy(c => c.NumberOfStudents).OrderBy(c => c.Key))
            {
                Console.WriteLine($"{coursesizes.Key},{coursesizes.Sum(s => s.Lectures)}");
            }

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

            model.Optimize();
            DisplayRoomStats("optimized", model.GetUsedRooms(), data);
        }
コード例 #4
0
ファイル: BasicTests.cs プロジェクト: lulzzz/UniTimetabling
        public void TestBudgetConstraintWithEnumeration(string filename, int budget, int seed)
        {
            var data        = Data.ReadXml(dataPath + filename, "120", "4");
            var formulation = ProblemFormulation.UD2NoOverbook;

            var comb = new RoomCombinations(data, 25);

            Console.WriteLine($"Minimum room is: {comb._minCost}");
            var newrooms = CreateRoomsFixedSize(data, 25, 1);

            data.SetRoomList(newrooms);


            var model = new CCTModel(data, formulation, new CCTModel.MIPModelParameters()
            {
                UseRoomsAsTypes = true,
                UseStageIandII  = false,
                TuneGurobi      = true,
                Seed            = seed,
            });

            //model.WriteModel(@"c:\temp\model.lp");
            //var budget = comb._minCost+0;


            Console.WriteLine($"Budget: {budget}");

            model.SetPossibleRoomCombinations(budget);
            model.Optimize(900);


            var sol = new Solution(data, formulation);

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

            Console.WriteLine($"Room Cost: {model.GetUsedRooms().Sum(kv => kv.Key.Cost*kv.Value)}");
            File.AppendAllText(@"c:\temp\enumtest.txt", $"{nameof(TestBudgetConstraintWithEnumeration)};{filename};{seed};{model.Objective}\n");
        }
コード例 #5
0
ファイル: BasicTests.cs プロジェクト: lulzzz/UniTimetabling
        public void TestBudgetConstraint(string filename, int budget, int seed)
        {
            var data        = Data.ReadXml(dataPath + filename, "120", "4");
            var formulation = ProblemFormulation.UD2NoOverbook;
            var newrooms    = CreateRoomsFixedSize(data, 25, 1);

            data.SetRoomList(newrooms);


            var model = new CCTModel(data, formulation, new CCTModel.MIPModelParameters()
            {
                UseRoomsAsTypes = true,
                UseStageIandII  = false,
                TuneGurobi      = true,
                Seed            = seed,
            });

            //model.WriteModel(@"c:\temp\model.lp");
            model.SetBudgetConstraint(budget);
            model.Optimize(900);
            Console.WriteLine($"Room Cost: {model.GetUsedRooms().Sum(kv => kv.Key.Cost * kv.Value)}");
            File.AppendAllText(@"c:\temp\enumtest.txt", $"{nameof(TestBudgetConstraint)};{filename};{seed};{model.Objective}\n");
        }
コード例 #6
0
        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");
        }