Пример #1
0
        static internal void OutputSolution(string directory)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            FileStream   fs = new FileStream(directory + "/movement_result.csv", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            sw.WriteLine("ID,FromLoc,ToLoc,FromTime,ToTime,VehicleID");
            foreach (Movement m in MovementList)
            {
                if (!m.IsActivated)
                {
                    continue;
                }

                ResourceSelectionGroup g = m.ResourceSelectionGroupSet.Find(x => x.ResourceType == typeof(Vehicle));
                Vehicle veh = g.SelectedResource as Vehicle;
                sw.WriteLine("{0},{1},{2},{3},{4},{5}", m.ID, m.FromLocation.ID, m.ToLocation.ID, m.FromTime, m.ToTime, veh.ID);
            }
            sw.Close();
            fs.Close();
        }
        public override void GenerateResourceSelectionGroup()
        {
            // Only vehicle resource
            ResourceSelectionGroup group = new ResourceSelectionGroup()
            {
                ID           = this.ResourceSelectionGroupSet.Count.ToString(),
                ResourceType = typeof(Vehicle),
                ResourceList = new List <Resource>()
                {
                    BindingVehicle
                },
            };

            ResourceSelectionGroupSet.Add(group);

            ResourceStatusRule rule = new ResourceStatusRule();

            group.ResourceStatusRuleList.Add(BindingVehicle, rule);

            // status
            var toTimePossibleStatus = BindingVehicle.PossibleResourceStatus.Find(x => ((VehicleStatus)x).HandlingMovement == this);

            rule.BindingStatusDict.Add(ToTime, new List <ResourceStatus>()
            {
                toTimePossibleStatus
            });

            if (FromTime != 0)
            {
                // previous status
                var fromTimePossibleStatus = BindingVehicle.PossibleResourceStatus.FindAll(
                    x => ((VehicleStatus)x).Location == FromLocation &&
                    ((VehicleStatus)x).HandlingMovement.ToTime == FromTime - 1);
                rule.NecessityStatusDict.Add(FromTime - 1, fromTimePossibleStatus);
            }

            if (ToTime != Parameters.TimeHorizon)
            {
                // next moment status
                var nextMomentPossibleStatus = BindingVehicle.PossibleResourceStatus.FindAll(x => ((VehicleStatus)x).Location == FromLocation &&
                                                                                             ((VehicleStatus)x).HandlingMovement.FromTime == ToTime + 1);
                rule.NecessityStatusDict.Add(ToTime + 1, nextMomentPossibleStatus);
            }
        }
Пример #3
0
        public override void GenerateResourceSelectionGroup()
        {
            // indicate which / how many resources a movement need

            // blocking section resource
            BlockSection bs = OnSegment.BindingBlockingSection;

            ResourceSelectionGroup bsResourceSelectionGroup = new ResourceSelectionGroup()
            {
                ID           = this.ResourceSelectionGroupSet.Count.ToString(),
                ResourceType = typeof(BlockSection),
                ResourceList = new List <Resource>()
                {
                    bs
                },
            };
            ResourceStatusRule rule   = new ResourceStatusRule();
            BlockSectionStatus status = (BlockSectionStatus)bs.PossibleResourceStatus.Find(x => ((BlockSectionStatus)x).HandlingMovement == this);

            for (int t = FromTime; t <= ToTime; t++)
            {
                rule.BindingStatusDict.Add(t, new List <ResourceStatus>()
                {
                    status
                });
                // if the movement is activated, only one status can be choosen.
            }

            bsResourceSelectionGroup.ResourceStatusRuleList.Add(bs, rule);
            ResourceSelectionGroupSet.Add(bsResourceSelectionGroup);


            // vehicle resource
            ResourceSelectionGroup vehicleResourceSelectionGroup = new ResourceSelectionGroup()
            {
                ID           = this.ResourceSelectionGroupSet.Count.ToString(),
                ResourceType = typeof(Vehicle),
            };

            foreach (Resource veh in DataRepository.ResourceList)
            {
                if (!(veh is Vehicle))
                {
                    continue;
                }

                vehicleResourceSelectionGroup.ResourceList.Add(veh);

                rule = new ResourceStatusRule();
                var statusSet = veh.PossibleResourceStatus.FindAll(x => ((VehicleStatus)x).HandlingMovement == this);

                var fromStatus  = statusSet.Find(x => ((VehicleStatus)x).Location == FromLocation);
                var toStatus    = statusSet.Find(x => ((VehicleStatus)x).Location == ToLocation);
                var onWayStatus = statusSet.Find(x => ((VehicleStatus)x).Location == Parameters.VirtualOnWayLocation);

                rule.BindingStatusDict.Add(FromTime, new List <ResourceStatus>()
                {
                    fromStatus
                });
                rule.BindingStatusDict.Add(ToTime, new List <ResourceStatus>()
                {
                    toStatus
                });

                for (int t = FromTime + 1; t < ToTime; t++)
                {
                    rule.BindingStatusDict.Add(t, new List <ResourceStatus>()
                    {
                        onWayStatus
                    });
                }

                // incoming resource status
                if (FromTime > 0)
                {
                    var incomingResourceStatus = veh.PossibleResourceStatus.FindAll(x => ((VehicleStatus)x).Location == FromLocation);
                    rule.NecessityStatusDict.Add(FromTime - 1, incomingResourceStatus);
                }

                vehicleResourceSelectionGroup.ResourceStatusRuleList.Add(veh, rule);
            }

            ResourceSelectionGroupSet.Add(vehicleResourceSelectionGroup);
        }