Ejemplo n.º 1
0
        public MapIcon(IconType type, MapDisplay parent, MapDragButton button)
        {
            this.col    = Color.Blue;
            this.radius = 5.0f;
            this.parent = parent;
            this.button = button;
            this.type   = type;

            ResourceManager resourcemanager
                = new ResourceManager("MyMap.Properties.Resources"
                                      , Assembly.GetExecutingAssembly());

            switch (type)
            {
            case IconType.Start:
                this.icon = new Bitmap((Image)resourcemanager.GetObject("start"));
                break;

            case IconType.End:
                this.icon = new Bitmap((Image)resourcemanager.GetObject("end"));
                break;

            case IconType.Via:
                this.icon = new Bitmap((Image)resourcemanager.GetObject("via"));
                break;

            case IconType.Bike:
                this.icon = new Bitmap((Image)resourcemanager.GetObject("bike"), 24, 24);
                break;

            case IconType.Car:
                this.icon = new Bitmap((Image)resourcemanager.GetObject("car"), 24, 24);
                break;
            }

            // If no vehicle is set make it foot.
            if (vehicle == null)
            {
                vehicle = new MyVehicle(MyMap.Vehicle.Foot, new Node(0, 0, 0));
            }

            if (button != null)
            {
                button.MapIcon = this;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a myVehicle of type v to the map.
        /// </summary>
        public void AddVehicle(MyVehicle v)
        {
            myVehicles.Add(v);
            MapIcon newIcon;

            switch (v.VehicleType)
            {
            case Vehicle.Car:
                newIcon          = new MapIcon(IconType.Car, this, null, v);
                newIcon.Location = v.Location;
                icons.Add(newIcon);
                CalcRoute();
                break;

            case Vehicle.Bicycle:
                newIcon          = new MapIcon(IconType.Bike, this, null, v);
                newIcon.Location = v.Location;
                icons.Add(newIcon);
                CalcRoute();
                break;
            }
        }
Ejemplo n.º 3
0
 public MapIcon(IconType type, MapDisplay parent, MapDragButton button, MyVehicle myVehicle)
     : this(type, parent, button)
 {
     this.vehicle = myVehicle;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds a myVehicle of type v to the map.
 /// </summary>
 public void AddVehicle(MyVehicle v)
 {
     myVehicles.Add(v);
     MapIcon newIcon;
     switch (v.VehicleType)
     {
         case Vehicle.Car:
             newIcon = new MapIcon(IconType.Car, this, null, v);
             newIcon.Location = v.Location;
             icons.Add(newIcon);
             CalcRoute();
             break;
         case Vehicle.Bicycle:
             newIcon = new MapIcon(IconType.Bike, this, null, v);
             newIcon.Location = v.Location;
             icons.Add(newIcon);
             CalcRoute();
             break;
     }
 }
Ejemplo n.º 5
0
 public MapIcon(IconType type, MapDisplay parent, MapDragButton button, MyVehicle myVehicle)
     : this(type, parent, button)
 {
     this.vehicle = myVehicle;
 }
Ejemplo n.º 6
0
        public MapIcon(IconType type, MapDisplay parent, MapDragButton button)
        {
            this.col = Color.Blue;
            this.radius = 5.0f;
            this.parent = parent;
            this.button = button;
            this.type = type;

            ResourceManager resourcemanager
            = new ResourceManager("MyMap.Properties.Resources"
                                 , Assembly.GetExecutingAssembly());

            switch (type)
            {
                case IconType.Start:
                    this.icon = new Bitmap((Image)resourcemanager.GetObject("start"));
                    break;
                case IconType.End:
                    this.icon = new Bitmap((Image)resourcemanager.GetObject("end"));
                    break;
                case IconType.Via:
                    this.icon = new Bitmap((Image)resourcemanager.GetObject("via"));
                    break;
                case IconType.Bike:
                    this.icon = new Bitmap((Image)resourcemanager.GetObject("bike"), 24, 24);
                    break;
                case IconType.Car:
                    this.icon = new Bitmap((Image)resourcemanager.GetObject("car"), 24, 24);
                    break;
            }

            // If no vehicle is set make it foot.
            if (vehicle == null)
                vehicle = new MyVehicle(MyMap.Vehicle.Foot, new Node(0, 0, 0));

            if (button != null)
                button.MapIcon = this;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the route through points "nodes" starting with Vehicles "vehicles",
        /// without using any vehicletype from "forbiddenVehicles" and using myVehicles "myVehicles".
        /// </summary>
        public Route CalcRoute(long[] nodes, List <Vehicle> vehicles, List <Vehicle> forbiddenVehicles, List <MyVehicle> myVehicles, RouteMode mode)
        {
            Route res = new Route(new Node[0], Vehicle.Foot);

            res.Length = double.PositiveInfinity;
            res.Time   = double.PositiveInfinity;

            Route  r   = null;
            double min = double.PositiveInfinity;

            for (int i = 0; i < myVehicles.Count; i++)
            {
                MyVehicle v = myVehicles[i];

                if (!forbiddenVehicles.Contains(v.VehicleType))
                {
                    // Calc route to the MyVehicle
                    List <MyVehicle> newMyVehicles = new List <MyVehicle>();
                    foreach (MyVehicle vNew in myVehicles)
                    {
                        if (vNew != v)
                        {
                            newMyVehicles.Add(vNew);
                        }
                    }

                    Route toVehicle = CalcRoute(new long[] { nodes[0], v.Location.ID }, vehicles, forbiddenVehicles, newMyVehicles, mode);

                    Route fromVehicle = null;

                    v.Route = toVehicle;

                    if (toVehicle != null && !Double.IsPositiveInfinity(toVehicle.Length))
                    {
                        // Calc route from MyVehicle through the given points
                        long[] through = new long[nodes.Length];
                        Array.Copy(nodes, through, nodes.Length);

                        through[0]  = v.Location.ID;
                        fromVehicle = CalcRoute(through, new List <Vehicle>()
                        {
                            v.VehicleType, Vehicle.Foot
                        }, forbiddenVehicles, newMyVehicles, mode);


                        // Route from source to destination using MyVehicle is
                        r = toVehicle + fromVehicle;


                        if (v.VehicleType == Vehicle.Bicycle)
                        {
                            r.Time += 60; //assuming it costs 1 minute to get your bicycle.
                        }
                        else if (v.VehicleType == Vehicle.Car)
                        {
                            r.Time += 4; //assumin it costs 4 minutes to get and park your car.
                        }
                    }

                    if (r != null && (r.Time < min && mode == RouteMode.Fastest || r.Length < min && mode == RouteMode.Shortest))
                    {
                        res = r;
                        switch (mode)
                        {
                        case RouteMode.Fastest:
                            min = r.Time;
                            break;

                        case RouteMode.Shortest:
                            min = r.Length;
                            break;
                        }
                    }
                }
            }


            if (nodes.Length >= 2)
            {
                r = Dijkstra(nodes[0], nodes[1], vehicles.ToArray(), mode, !forbiddenVehicles.Contains(Vehicle.Bus));

                if (nodes.Length > 2)
                {
                    r += CalcRoute(SubArray(nodes, 1, nodes.Length), vehicles, forbiddenVehicles, myVehicles, mode);
                }
            }

            if (r != null && (r.Time <= min && mode == RouteMode.Fastest || r.Length <= min && mode == RouteMode.Shortest))
            {
                res = r;
            }

            return(res);
        }