Changeset 16724


Ignore:
Timestamp:
Aug 31, 2017, 12:04:36 PM (2 years ago)
Author:
dramos
Message:

back-end final

Location:
internals/2017/ScheduleOptimizer/backend/WSListener
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • internals/2017/ScheduleOptimizer/backend/WSListener/SS.DAL/BL/SolarSchedulerBL.cs

    r16708 r16724  
    5151        public WeeklyScheduleDTO OptimizeWeek(int temperature, int times, int tries, bool ignoreAreas, int year, int month, int day, int costSelect)
    5252        {
     53            Optimizer.Optimizer.ToChange.RemoveAll(tuple => true);
    5354            DateTime date = new DateTime(year, month, day);
    5455            List <Task<List<DailyScheduleDTO>>> tasks = new List<Task<List<DailyScheduleDTO>>>();
     
    7475
    7576            return new WeeklyScheduleDTO(result, ignoreAreas);
     77        }
     78
     79        public bool RescheduleWeek()
     80        {
     81            solarschedulerEntities context = new solarschedulerEntities();
     82
     83            if (context.Database.Connection.State != ConnectionState.Open)
     84            {
     85                context.Database.Connection.Open();
     86            }
     87            foreach (var t in Optimizer.Optimizer.ToChange)
     88            {
     89                var postSchedule = t.Item2;
     90
     91                foreach (Appointment app in postSchedule.Appointments)
     92                {
     93                    int processId = app.ProcessId;
     94                    process proc = context.process.Where(pro => pro.Id.Equals(processId)).First();
     95                    proc.InstallationTeam_Id = app.AssignedTeam.TeamId;
     96                    proc.TravelTime = app.Cost;
     97                    string strScheduled = Utils.State.SCHEDULED.ToString();
     98                    if (proc.State.Equals(strScheduled))
     99                        proc.ScheduleHour = app.ScheduledHour;
     100                    else
     101                        proc.ReScheduleHour = app.ScheduledHour;
     102
     103                }
     104            }
     105            context.SaveChanges();
     106            return true;
    76107        }
    77108
     
    20592090            bestSchedule.TotalWastedTime = idleTime.SolutionQuality(bestSchedule);
    20602091            bestSchedule.TotalPriorityCount = priority.SolutionQuality(bestSchedule);
     2092            Optimizer.Optimizer.Save(new Tuple<DailySchedule, DailySchedule>(defaultSchedule, bestSchedule));
    20612093            // ReSchedule(defaultSchedule, bestSchedule);
    20622094
     
    20692101            return lst;
    20702102           
    2071         }
    2072 
    2073         public void ReSchedule(DailySchedule preSchedule, DailySchedule postSchedule)
    2074         {
    2075             solarschedulerEntities context = new solarschedulerEntities();
    2076 
    2077             if (context.Database.Connection.State != ConnectionState.Open)
    2078             {
    2079                 context.Database.Connection.Open();
    2080             }
    2081 
    2082 
    2083             foreach (Appointment app in postSchedule.Appointments)
    2084             {
    2085                 int processId = app.ProcessId;
    2086                 process proc = context.process.Where(pro => pro.Id.Equals(processId)).First();
    2087                 proc.InstallationTeam_Id = app.AssignedTeam.TeamId;
    2088                 proc.TravelTime = app.Cost;
    2089                 string strScheduled = Utils.State.SCHEDULED.ToString();
    2090                 if (proc.State.Equals(strScheduled))
    2091                     proc.ScheduleHour = app.ScheduledHour;
    2092                 else
    2093                     proc.ReScheduleHour = app.ScheduledHour;
    2094                
    2095             }
    2096 
    2097             context.SaveChanges();
    20982103        }
    20992104
  • internals/2017/ScheduleOptimizer/backend/WSListener/SS.DAL/Optimizer/CostFunctions/IldeCountCostFunction.cs

    r16708 r16724  
    1111    class IldeCountCostFunction : ICostFunction
    1212    {
    13         public static int TIMELIMIT = 3;
     13        public static int TIMELIMIT = 2;
    1414
    1515        double ICostFunction.SolutionQuality(DailySchedule schedule)
  • internals/2017/ScheduleOptimizer/backend/WSListener/SS.DAL/Optimizer/Optimizer.cs

    r16708 r16724  
    1616    public class Optimizer
    1717    {
    18         private static void SimulatedAnnealing(DailySchedule schedule, int initialTemperature = 1, int times = 10000, double alfa = 0.99)
     18        public static List<Tuple<DailySchedule, DailySchedule>> ToChange = new List<Tuple<DailySchedule, DailySchedule>>();
     19
     20        private static DailySchedule SimulatedAnnealing(DailySchedule schedule, int initialTemperature = 1, int times = 10000, double alfa = 0.99)
    1921        {
     22            DailySchedule bestSchedule = schedule;
    2023            Random rng = new Random();
    2124            for (int i = 0; i < times; i++)
     
    4144
    4245                double temperature = initialTemperature / Math.Log(1.1 + i);
     46                if (newCost < bestSchedule.Cost())
     47                    bestSchedule = ObjectCopier.Clone<DailySchedule>(schedule);
     48
    4349                if (oldCost - newCost < 0 && rng.NextDouble() > Math.Exp((oldCost - newCost) / temperature))
    4450                {
     
    4955
    5056            }
     57
     58            return bestSchedule;
    5159        }
    5260
     
    6068                {
    6169                    DailySchedule dailySchedule = ObjectCopier.Clone<DailySchedule>(defaultSchedule);
    62                     SimulatedAnnealing(dailySchedule, temperature, times);
     70                    dailySchedule = SimulatedAnnealing(dailySchedule, temperature, times);
    6371                    return dailySchedule;
    6472                });
     
    93101
    94102        public static LocationCache LocatCache = new LocationCache();
     103
     104        public static void Save(Tuple<DailySchedule, DailySchedule> tuple)
     105        {
     106            ToChange.Add(tuple);
     107        }
    95108    }
    96109}
  • internals/2017/ScheduleOptimizer/backend/WSListener/SS.DAL/obj/Debug/SS.DAL.csproj.FileListAbsolute.txt

    r16708 r16724  
    2424D:\Users\afonso.ribeiro\workspace\backend\WSListener\SS.DAL\obj\Debug\SS.DAL.dll
    2525D:\Users\afonso.ribeiro\workspace\backend\WSListener\SS.DAL\obj\Debug\SS.DAL.pdb
    26 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\SS.DAL.dll.config
    27 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\SS.DAL.dll
    28 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\SS.DAL.pdb
    29 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\CsvHelper.dll
    30 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\DataAnnotationsExtensions.dll
    31 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\DevTrends.WCFDataAnnotations.dll
    32 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\EntityFramework.dll
    33 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\EntityFramework.SqlServer.dll
    34 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\log4net.dll
    35 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\MySql.Data.dll
    36 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\MySql.Data.Entity.EF6.dll
    37 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\MySql.Web.dll
    38 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\PagedList.dll
    39 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\RabbitMQ.Client.dll
    40 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\CsvHelper.pdb
    41 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\CsvHelper.xml
    42 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\DevTrends.WCFDataAnnotations.pdb
    43 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\EntityFramework.xml
    44 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\EntityFramework.SqlServer.xml
    45 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\log4net.xml
    46 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\MySql.Data.Entity.EF6.xml
    47 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\PagedList.xml
    48 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\bin\Debug\RabbitMQ.Client.xml
    49 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\obj\Debug\SS.DAL.dll
    50 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\SS.DAL\obj\Debug\SS.DAL.pdb
  • internals/2017/ScheduleOptimizer/backend/WSListener/WSSolarScheduler/ISolarSchedulerService.cs

    r16708 r16724  
    205205        List<DailyScheduleDTO> OptimizeDay(int temperature, int times, int tries, bool ignoreAreas, int year, int month, int day, int costSelect);
    206206
    207 
    208207        [OperationContract]
    209208        WeeklyScheduleDTO OptimizeWeek(int temperature, int times, int tries, bool ignoreAreas, int year, int month, int day, int costSelect);
     209
     210        [OperationContract]
     211        bool RescheduleWeek();
    210212    }
    211213
  • internals/2017/ScheduleOptimizer/backend/WSListener/WSSolarScheduler/SolarSchedulerService.svc.cs

    r16708 r16724  
    3131        }
    3232
     33        public bool RescheduleWeek()
     34        {
     35            SolarSchedulerBL solarSchedulerBL = new SolarSchedulerBL();
     36            return solarSchedulerBL.RescheduleWeek();
     37        }
     38
    3339        public CountyResult GetCounty(string sessionToken, string zipCode, string ext)
    3440        {
  • internals/2017/ScheduleOptimizer/backend/WSListener/WSSolarScheduler/obj/Debug/WSSolarScheduler.csproj.FileListAbsolute.txt

    r16708 r16724  
    1818D:\Users\afonso.ribeiro\workspace\backend\WSListener\WSSolarScheduler\obj\Debug\WSSolarScheduler.dll
    1919D:\Users\afonso.ribeiro\workspace\backend\WSListener\WSSolarScheduler\obj\Debug\WSSolarScheduler.pdb
    20 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\WSSolarScheduler.dll.config
    21 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\WSSolarScheduler.dll
    22 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\WSSolarScheduler.pdb
    23 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\DevTrends.WCFDataAnnotations.dll
    24 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\EntityFramework.dll
    25 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\EntityFramework.SqlServer.dll
    26 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\MySql.Data.dll
    27 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\MySql.Data.Entity.EF6.dll
    28 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\MySql.Web.dll
    29 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\SS.DAL.dll
    30 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\log4net.dll
    31 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\SS.DAL.pdb
    32 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\SS.DAL.dll.config
    33 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\DevTrends.WCFDataAnnotations.pdb
    34 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\EntityFramework.xml
    35 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\EntityFramework.SqlServer.xml
    36 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\bin\log4net.xml
    37 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\obj\Debug\WSSolarScheduler.csprojResolveAssemblyReference.cache
    38 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\obj\Debug\WSSolarScheduler.dll
    39 C:\Users\Daniel\Desktop\CM\bk_paula\backend\WSListener\WSSolarScheduler\obj\Debug\WSSolarScheduler.pdb
Note: See TracChangeset for help on using the changeset viewer.