Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string ars    = System.IO.File.ReadAllText(@"day1_0/ARs.json");
            string dtos   = System.IO.File.ReadAllText(@"day1_0/DTOs.json");
            string consts = System.IO.File.ReadAllText(@"day1_0/constants.json");

            List <AR>  ARlist    = JsonConvert.DeserializeObject <List <AR> >(ars);
            List <DTO> DTOlist   = JsonConvert.DeserializeObject <List <DTO> >(dtos);
            Costants   constlist = JsonConvert.DeserializeObject <Costants>(consts);

            max_mem = constlist.MEMORY_CAP;

            //merge AR con DTO
            List <ARDTO> ar_dto = new List <ARDTO>();

            DTOlist.ForEach(d =>
            {
                ARDTO ardto = new ARDTO(ARlist.Find(a => a.id == d.ar_id), d);
                ar_dto.Add(ardto);
            });

            GeneratePlans(ar_dto);

            Console.WriteLine("\nSTOP");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        // Creazione di un piano con una lista randomizzata
        public void BuildPlan()
        {
            bool ok; //indica se i vincoli sono rispettati
            int  i = 0;

            if (current_mem == 0)
            {
                plan.Add(instance.GetARDTO(0));
                current_mem += plan[0].memory;
                i++;
            }
            //Console.WriteLine("id_ar\t\tid_dto\t\trank\thigh\tstart\t\t\tstop\t\t\tmemory");

            int n = instance.GetARDTOs().Count;

            for (; i < n; i++)
            {
                ARDTO newArdto = instance.GetARDTO(i);
                ok = true;
                int j;
                for (j = 0; j < plan.Count; j++)
                {
                    //controllo che non ci sia un overlap temporale con i precedenti
                    if (newArdto.stop_time >= plan[j].start_time &&
                        newArdto.start_time <= plan[j].stop_time)
                    {
                        ok = false;
                        break;
                    }
                    //controllo che l'id_ar non sia già presente in quelli aggiunti
                    if (newArdto.id_ar == plan[j].id_ar)
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                {
                    //controllo memoria libera
                    if (current_mem + newArdto.memory <= instance.GetMaxMem())
                    {
                        //ardto[i].PrintAll();
                        plan.Add(newArdto);
                        current_mem += newArdto.memory;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Instance(string ars, string dtos, string consts, int seed)
        {
            List <AR>  ARlist    = JsonConvert.DeserializeObject <List <AR> >(ars);
            List <DTO> DTOlist   = JsonConvert.DeserializeObject <List <DTO> >(dtos);
            Costants   constlist = JsonConvert.DeserializeObject <Costants>(consts);

            rnd = new Random(seed);

            max_mem  = constlist.MEMORY_CAP;
            max_rank = constlist.RANK;

            //merge AR con DTO
            ar_dto = new List <ARDTO>();
            DTOlist.ForEach(d =>
            {
                ARDTO ardto = new ARDTO(ARlist.Find(a => a.id == d.ar_id), d);
                ar_dto.Add(ardto);
            });
        }