Beispiel #1
0
        public State Run(Act act)
        {
            var result = new State(this);

            result.Location = act.to;
            result.timeLeft -= act.timecost;
            if (act.daypass >= 1)
            {
                result.day += act.daypass;
                result.timeLeft = TimeSpan.FromHours(12);

            }
            return result;
        }
Beispiel #2
0
 public State(State cpy)
 {
     Location = cpy.Location;
     day = cpy.day;
     timeLeft = cpy.timeLeft;
 }
Beispiel #3
0
 public State Apply(State temp, Act act)
 {
     State result = new State(temp);
     result = result.Run(act);
     pastActs.Add(act);
     if (act.daypass >= 1)
     {
         alldaypass += act.daypass;
     }
     return result;
 }
Beispiel #4
0
        public State Travel(State initialState, Node destination)
        {
            ///            State result = new State(initialState);

            State temp = new State(initialState);

            if(temp.Location == destination&&destination ==root)
            {
                pastActs.Add(new Act(root, root, 1, new TimeSpan()));
                temp.day = 1;
                currentState = temp;
                return temp;

            }

            while (temp.Location!= destination)
            {
                ///debug
                if (this.pastActs.Count > 0)
                {
                    if (this.pastActs.Last().daypass > 2)
                    {  temp.day = 16;
                    currentState.day = 16;
                    currentState = temp;
                    return temp;
                }
                }

                if (alldaypass > 500)
                {
                    temp.day = 16;
                    currentState.day = 16;
                    currentState = temp;
                    return temp;
                }

                temp.SetPossbileAct(root,destination);
                TimeSpan optm = TimeSpan.FromHours(999);
                Act optmA=new Act();
                List<City> cityNeardestination=new List<City>();
                if(destination is City)
                {
                    cityNeardestination.Add((City)destination);
                }
                if (destination is Resort)
                {
                    Resort r = (Resort)destination;
                    cityNeardestination = r.CityNear;

                }
                City optmCity = new City();
                if (temp.Location is Resort ||destination is City)
                {
                    foreach (City cityNear in cityNeardestination)
                    {
                        TimeSpan addition = TimeSpan.FromHours(0);
                        if (destination is Resort)
                        {
                            Resort r = (Resort)destination;
                            addition = r.CityNearTime.ElementAt(r.CityNear.IndexOf(cityNear));
                        }
                        foreach (Act act in temp.possbileAct)
                        {

                            TimeSpan newOptm = TimeSpan.FromHours(Length(temp.Run(act).Location, cityNear) / 90) + addition;
                            if (newOptm < optm)
                            {
                                optm = newOptm;
                                optmCity = cityNear;
                                optmA = act;

                            }

                        }

                    }
                }

                if (destination is Resort && temp.Run(temp.possbileAct.First()).Location == destination)
                {
                    optmA = temp.possbileAct.First();
                    //temp = Apply(temp, optmA);
                    //currentState = temp;
                    //return temp;
                }
                else
                {
                    //debug
                    if (destination.name == "拉萨大昭寺景区")
                    {
                        ;
                    }

                    if (destination is Resort  &&  temp.Location is City)
                    {
                        foreach (City cityNear in cityNeardestination)
                        {
                            TimeSpan addition = TimeSpan.FromHours(0);
                            if (destination is Resort)
                            {
                                Resort r = (Resort)destination;
                                addition = r.CityNearTime.ElementAt(r.CityNear.IndexOf(cityNear));
                            }
                            foreach (Act act in temp.possbileAct)
                            {

                                TimeSpan newOptm = TimeSpan.FromHours(Length(temp.Run(act).Location, cityNear) / 90) + addition;
                                if (newOptm < optm)
                                {
                                    optm = newOptm;
                                    optmCity = cityNear;
                                    optmA = act;
                                }

                            }

                        }
                    }
                }

                if (optmA.timecost >= TimeSpan.FromHours(8))
                {
                    optmA = new Act(optmA.from, optmA.to, optmA.daypass+1, optmA.timecost - TimeSpan.FromHours(8));
                }
                if (optmA.timecost >= TimeSpan.FromHours(8))
                {
                    optmA = new Act(optmA.from, optmA.to, optmA.daypass+1, optmA.timecost - TimeSpan.FromHours(8));
                }

                if (temp.Location is City && destination is Resort&& temp.Run(optmA).Location is City && temp.Run(temp.possbileAct.First()).Location != destination)
                {
                    var r = (Resort)destination;
                    int better = 0;
                    Node bestD = optmA.to;
                    double record;
                    foreach (City c in r.CityNear)
                    {
                        if ( Length(temp.Run(optmA).Location, c) >= Length(temp.Location, c))
                        {
                            better = 1;
                            record = Length(temp.Run(optmA).Location, c);

                        }
                    }
                    if (better==0) {
                        TimeSpan best=new TimeSpan();

                        TimeSpan compare;
                        foreach (City c in r.CityNear)
                        {
                            compare=TimeSpan.FromHours(Length(temp.Run(optmA).Location, c)/90)+  r.CityNearTime.ElementAt(r.CityNear.IndexOf(c));
                            if (best == null)
                            {
                                best = compare;
                                bestD = c;
                            }

                            if (compare < best)
                            {
                                best = compare;
                                bestD = c;
                            }
                        }

                        optmA = new Act(optmA.from, bestD, optmA.daypass, TimeSpan.FromHours(Length(temp.Location, bestD) / 90) );
                    }
                }

                if (temp.Location is City && destination is City)
                {
                    if (Length(temp.Run(optmA).Location, destination) > Length(temp.Location, destination))
                    {
                        optmA = new Act(optmA.from, destination, 1, TimeSpan.FromHours(Length(temp.Location, destination)/90) - TimeSpan.FromHours(8));
                        if (optmA.timecost >= TimeSpan.FromHours(8))
                        {
                            optmA = new Act(optmA.from, destination, optmA.daypass + 1, optmA.timecost - TimeSpan.FromHours(8));
                        }
                        if (optmA.timecost >= TimeSpan.FromHours(8))
                        {
                            optmA = new Act(optmA.from, destination, optmA.daypass + 1, optmA.timecost - TimeSpan.FromHours(8));
                        }
                    }

                }

                if (destination is Resort && temp.Run(temp.possbileAct.First()).Location == destination)
                {
                    optmA = temp.possbileAct.First();
                    //temp = Apply(temp, optmA);
                    //currentState = temp;
                    //return temp;
                }

                if (optmA.timecost >= TimeSpan.FromHours(8))
                {
                    optmA = new Act(optmA.from, optmA.to, optmA.daypass + 1, optmA.timecost - TimeSpan.FromHours(8));
                }
                if (optmA.timecost >= TimeSpan.FromHours(8))
                {
                    optmA = new Act(optmA.from, optmA.to, optmA.daypass + 1, optmA.timecost - TimeSpan.FromHours(8));
                }

                temp = Apply(temp,optmA);
            }
            if(temp.Location is Resort)
            {
                Resort r = (Resort)destination;
                if (r.deftime == TimeSpan.FromHours(2))
                {
                    temp = Apply(temp, new Act(destination, destination, 0, TimeSpan.FromHours(1)));
                    temp = Apply(temp, new Act(destination, destination, 1, new TimeSpan()));
                    temp = Apply(temp, new Act(destination, destination, 0, TimeSpan.FromHours(1)));
                }
                else
                {
                    temp = Apply(temp, new Act(destination, destination, 0, r.deftime));
                }

            }

            currentState = temp;
            return temp;
        }
Beispiel #5
0
 public TravelPlan(Node root)
 {
     this.root = root;
     currentState = new State(root);
 }