コード例 #1
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
            }
        }