Beispiel #1
0
        private List <OptimizeLib.Model.Vehicle> AssigmentEq()
        {
            //var rnd = new Random();
            //for (var i = 0; i < 100; i++)
            //{
            //    var companyId = 1 + rnd.Next(10);
            //    DatabaseHelper.CreateTask(1, "Разгребание валов снега", companyId, rnd.Next(10) * 1000);
            //    DatabaseHelper.CreateTask(2, "Убрать дорогу", companyId, rnd.Next(10) * 1000);
            //    DatabaseHelper.CreateTask(3, "Сколоть снег", companyId, rnd.Next(10) * 1000);
            //    DatabaseHelper.CreateTask(4, "Сколоть снег", companyId, rnd.Next(10) * 1000);
            //    DatabaseHelper.CreateTask(5, "Разгребание валов снега", companyId, rnd.Next(10) * 1000);
            //}

            //DatabaseHelper.CreateTask(2, "Убрать дорогу", 1, 80000);
            //DatabaseHelper.CreateTask(3, "Сколоть снег", 2, 60000);
            //DatabaseHelper.CreateTask(4, "Разгребание валов снега на перекрёстках", 3, 40000);
            //DatabaseHelper.CreateTask(5, "Разгребание валов снега на остановках пассажирского транспорта", 4, 50000);
            //DatabaseHelper.CreateTask(2, "Убрать дорогу", 5, 80000);
            //DatabaseHelper.CreateTask(3, "Сколоть снег", 6, 60000);
            //DatabaseHelper.CreateTask(4, "Сколоть снег", 7, 40000);
            //DatabaseHelper.CreateTask(5, "Разгребание валов снега на остановках пассажирского транспорта", 8, 50000);

            // TaskID = DatabaseHelper.CreateTask(1, "Тестовая задача", 10);
            var assignment = DatabaseHelper.LoadAssignmentInput(Tasks);

            List <Tuple <int, EquipmentCompatibility> > listVT  = new List <Tuple <int, EquipmentCompatibility> >();
            List <Tuple <int, EquipmentCompatibility> > listEqT = new List <Tuple <int, EquipmentCompatibility> >();

            //Dictionary<int, EquipmentCompatibility> listVT = new Dictionary<int, EquipmentCompatibility>();
            //Dictionary<int, EquipmentCompatibility> listEqT = new Dictionary<int, EquipmentCompatibility>();

            foreach (var comp in assignment.Compatibility)
            {
                if (!listVT.Any((g) => g.Item1 == comp.VehicleTypeId))
                {
                    listVT.Add(new Tuple <int, EquipmentCompatibility>(comp.VehicleTypeId, comp));
                }

                if (!listEqT.Any((g) => g.Item1 == comp.EquipmentTypeId))
                {
                    listEqT.Add(new Tuple <int, EquipmentCompatibility>(comp.EquipmentTypeId, comp));
                }
            }

            int countRows    = listVT.Count();
            int countColumns = listEqT.Count();

            int[,] a  = new int[countRows, countColumns];
            int[,] ba = new int[countRows, countColumns];

            for (int i = 0; i < countRows; i++)
            {
                int idV = listVT[i].Item1;
                for (int j = 0; j < countColumns; j++)
                {
                    int idE = listEqT[j].Item1;

                    var f = assignment.Compatibility.FirstOrDefault((b) => b.VehicleTypeId == idV && b.EquipmentTypeId == idE);
                    a[i, j]  = f == null ? int.MaxValue : (int)Math.Ceiling(f.Factor);
                    ba[i, j] = a[i, j];
                }
            }

            List <OptimizeLib.Model.Vehicle> lvv = new List <OptimizeLib.Model.Vehicle>();

            var ddd = Assignment.Assign.Compute(ba, countRows, countColumns);

            gvEq.AutoGenerateColumns = false;
            gvEq.RowCount            = countRows;
            gvEq.ColumnCount         = countColumns;
            gvEq.RowHeadersWidth     = 200;

            for (int i = 0; i < countRows; i++)
            {
                gvEq.Rows[i].HeaderCell.Value = listVT[i].Item2.VehicleType.Name;
                for (int j = 0; j < countColumns; j++)
                {
                    if (i == 0)
                    {
                        gvEq.Columns[j].Name = listEqT[j].Item2.EquipmentType.Name;
                    }

                    gvEq.Rows[i].Cells[j].Value           = a[i, j] == int.MaxValue ? "-" : a[i, j].ToString();
                    gvEq.Rows[i].Cells[j].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
            }

            foreach (var d in ddd)
            {
                var fVT = listVT[d.Item1];
                var fEq = listEqT[d.Item2];

                OptimizeLib.Model.Vehicle v = new OptimizeLib.Model.Vehicle
                {
                    EqTypeId      = fEq.Item1,
                    VehicleTypeId = fVT.Item1,
                    Name          = fVT.Item2.VehicleType.Name + " + " + fEq.Item2.EquipmentType.Name,
                };

                gvEq.Rows[d.Item1].Cells[d.Item2].Style.BackColor = Color.LightGreen;
                lvv.Add(v);
            }

            return(lvv);
        }
Beispiel #2
0
        private List <OptimizeLib.Model.Vehicle> AssigmentEq()
        {
            var assignment = DatabaseHelper.LoadAssignmentInput(Tasks);

            List <Tuple <int, EquipmentCompatibility> > listVT  = new List <Tuple <int, EquipmentCompatibility> >();
            List <Tuple <int, EquipmentCompatibility> > listEqT = new List <Tuple <int, EquipmentCompatibility> >();

            foreach (var comp in assignment.Compatibility)
            {
                if (!listVT.Any((g) => g.Item1 == comp.VehicleTypeId))
                {
                    listVT.Add(new Tuple <int, EquipmentCompatibility>(comp.VehicleTypeId, comp));
                }

                if (!listEqT.Any((g) => g.Item1 == comp.EquipmentTypeId))
                {
                    listEqT.Add(new Tuple <int, EquipmentCompatibility>(comp.EquipmentTypeId, comp));
                }
            }

            int countRows    = listVT.Count();
            int countColumns = listEqT.Count();

            int[,] a  = new int[countRows, countColumns];
            int[,] ba = new int[countRows, countColumns];

            for (int i = 0; i < countRows; i++)
            {
                int idV = listVT[i].Item1;
                for (int j = 0; j < countColumns; j++)
                {
                    int idE = listEqT[j].Item1;

                    var f = assignment.Compatibility.FirstOrDefault((b) => b.VehicleTypeId == idV && b.EquipmentTypeId == idE);
                    a[i, j]  = f == null ? int.MaxValue : (int)Math.Ceiling(f.Factor);
                    ba[i, j] = a[i, j];
                }
            }

            List <OptimizeLib.Model.Vehicle> lvv = new List <OptimizeLib.Model.Vehicle>();

            var ddd = Assignment.Assign.Compute(ba, countRows, countColumns);

            gvEq.AutoGenerateColumns = false;
            gvEq.RowCount            = countRows;
            gvEq.ColumnCount         = countColumns;
            gvEq.RowHeadersWidth     = 200;

            for (int i = 0; i < countRows; i++)
            {
                gvEq.Rows[i].HeaderCell.Value = listVT[i].Item2.VehicleType.Name;
                for (int j = 0; j < countColumns; j++)
                {
                    if (i == 0)
                    {
                        gvEq.Columns[j].Name = listEqT[j].Item2.EquipmentType.Name;
                    }

                    gvEq.Rows[i].Cells[j].Value           = a[i, j] == int.MaxValue ? "-" : a[i, j].ToString();
                    gvEq.Rows[i].Cells[j].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
            }

            foreach (var d in ddd)
            {
                var fVT = listVT[d.Item1];
                var fEq = listEqT[d.Item2];

                OptimizeLib.Model.Vehicle v = new OptimizeLib.Model.Vehicle
                {
                    EqTypeId      = fEq.Item1,
                    VehicleTypeId = fVT.Item1,
                    Name          = fVT.Item2.VehicleType.Name + " + " + fEq.Item2.EquipmentType.Name,
                };

                gvEq.Rows[d.Item1].Cells[d.Item2].Style.BackColor = Color.LightGreen;
                lvv.Add(v);
            }

            return(lvv);
        }