static void Main(string[] args)
        {
            // output all neighborhoods in data
            Query     query     = new Query();
            Manhattan manhattan = query.JsonConversionGetData();

            Console.WriteLine("----------");
            Console.WriteLine("Output all neighborhoods in data list");
            query.GetNeighborhoods(manhattan);

            // filter out neighborhoods that do not have names
            Console.WriteLine("----------");
            Console.WriteLine("Filter out all neighborhoods that do not have names");
            query.FilterNeighborhoods(manhattan);

            // remove duplicates
            Console.WriteLine("----------");
            Console.WriteLine("Remove duplicates");
            query.RemoveDuplicates(manhattan);

            // filter out neighborhoods that do not have names
            Console.WriteLine("----------");
            Console.WriteLine("Remove duplicates");
            Console.WriteLine("Filter out all neighborhoods that do not have names");
            query.RemoveDuplicateOfNeighborhoodWithoutNames(manhattan);

            // run method that was rewritten to remove duplicates using LINQ
            Console.WriteLine("----------");
            Console.WriteLine("Using LINQ");
            query.ChangeToLINQ(manhattan);
        }
        private List <Sector> FindSectorsNearPlayer()
        {
            TilePosition playerTilePosition = Graphics.Vector3ToTilePosition(player.position);

            TilePosition playerSectorTilePosition = sectorManager.GetSectorTile(playerTilePosition).sectorPosition;

            List <Sector> sectorsNear = new List <Sector>();

            int visibileSectorsRadius = (int)Math.Ceiling(playerUnity.mainCamera.farClipPlane / SectorManager.SECTOR_SIZE) + 1;

            for (int d = 0; d <= visibileSectorsRadius; d++)
            {
                foreach (TilePosition tilePosition in Manhattan.GetTilesAtDistance(d))
                {
                    TilePosition t = tilePosition + playerSectorTilePosition;

                    if (t.x >= 0 && t.x < sectorManager.xSectors &&
                        t.y >= 0 && t.y < sectorManager.ySectors &&
                        t.z >= 0 && t.z < sectorManager.zSectors)
                    {
                        sectorsNear.Add(sectorManager.GetSector(t));
                    }
                }
            }

            return(sectorsNear);
        }
Beispiel #3
0
        /// <summary>
        /// reads in a json file and converts contents to a JObject
        /// </summary>
        /// <param name="data"> 'features' list from json data </param>
        /// <returns> JSON object made from data file contents </returns>
        static Feature[] ReadFile(string path)
        {
            string    source = File.ReadAllText(path);
            Manhattan data   = JsonConvert.DeserializeObject <Manhattan>(source);

            return(data.features);
        }
Beispiel #4
0
        public void AStarTest()
        {
            HeuristicProvider heuristicProvider = new Manhattan(solution);
            IFinder           finder            = new AStar(heuristicProvider);

            Assert.IsNotNull(finder);
        }
        public void FilterNoNameNeighborhood(Manhattan manhattan)
        {
            var neighborhoods = manhattan.Features.Select(x => x.Properties).Select(x => x.Neighborhood).Where(x => x != "");

            foreach (string neighborhood in neighborhoods)
            {
                Console.WriteLine(neighborhood);
            }
        }
        public void OutputNeighborhood(Manhattan manhattan)
        {
            var neighborhoods = manhattan.Features.Select(x => x.Properties).Select(x => x.Neighborhood);

            foreach (string neighborhood in neighborhoods)
            {
                Console.WriteLine(neighborhood);
            }
        }
        public void RemoveDuplicateAndNoNameNeighborhood(Manhattan manhattan)
        {
            var neighborhoods = manhattan.Features.Select(x => x.Properties).Select(x => x.Neighborhood).Where(x => x != "").Distinct();

            foreach (var neighborhood in neighborhoods)
            {
                Console.WriteLine(neighborhood);
            }
        }
Beispiel #8
0
        private static void ExercisesLessonOne()
        {
            var listX = new List <double>();

            listX.Add(4);
            listX.Add(2);
            Vector x = new Vector(listX);

            var listAmy = new List <double>();

            listAmy.Add(5);
            listAmy.Add(5);
            Vector amy = new Vector(listAmy);

            var listClara = new List <double>();

            listClara.Add(4.75);
            listClara.Add(4.5);
            listClara.Add(5);
            listClara.Add(4.25);
            listClara.Add(4);
            Vector clara = new Vector(listClara);

            var listRobert = new List <double>();

            listRobert.Add(4);
            listRobert.Add(3);
            listRobert.Add(5);
            listRobert.Add(2);
            listRobert.Add(1);
            Vector robert = new Vector(listRobert);

            var listAmy2 = new List <double>();

            listAmy2.Add(3.0);
            Vector amyTwo = new Vector(listAmy2);

            var listX2 = new List <double>();

            listX2.Add(5.0);
            listX2.Add(2.5);
            listX2.Add(2.0);
            Vector xTwo = new Vector(listX2);

            var one   = new Euclidian().Calculate(amy, x);
            var two   = new Manhattan().Calculate(amy, x);
            var three = new Pearson().Calculate(clara, robert);
            var four  = new Cosine().Calculate(clara, robert);
            var five  = new Cosine().Calculate(amyTwo, xTwo);

            Console.WriteLine("\nEuclidian between Amy and X = " + one);
            Console.WriteLine("Manhattan between Amy and X = " + two);
            Console.WriteLine("Pearson between Clara and Robert = " + three);
            Console.WriteLine("Cosine between Clara and Robert = " + four);
            Console.WriteLine("Cosine between Amy and X (incomplete) = " + five);
        }
        public void RewriteWithLINQ(Manhattan manhattan)
        {
            var neighborhoods = (from features in manhattan.Features
                                 where features.Properties.Neighborhood != ""
                                 select features.Properties.Neighborhood).Distinct();

            foreach (var neighborhood in neighborhoods)
            {
                Console.WriteLine(neighborhood);
            }
        }
        public Manhattan GetManhattanData()
        {
            string text = "";

            using (StreamReader sr = File.OpenText(DATA_FILE_PATH))
            {
                text = sr.ReadToEnd();
            }

            Manhattan data = JsonConvert.DeserializeObject <Manhattan>(text);

            return(data);
        }
Beispiel #11
0
        public void AlgorithmManhattanHeuristicTest()
        {
            byte[]            puzzle            = new byte[] { 1, 2, 3, 4, 5, 11, 0, 7, 9, 6, 10, 8, 13, 14, 15, 12 };
            HeuristicProvider heuristicProvider = new Manhattan(solution);
            GraphExplorer     explorer          = GraphExplorer.CreateGraphExplorer(
                new byte[] { 4, 4 },
                puzzle,
                new char[] { 'u', 'd', 'l', 'r' }, new AStar(heuristicProvider));

            explorer.TargetState = new NodeState(new byte[] { 4, 4 },
                                                 new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 });
            string sol = explorer.TraverseForSolution();

            Assert.IsFalse(string.IsNullOrEmpty(sol));
        }
Beispiel #12
0
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;
            int amount = 0;

            foreach (TilePosition delta in Manhattan.GetTilesAtDistance(1))
            {
                if (tileManager.IsValidTile(pos + delta) && tileManager.GetTileType(pos + delta) == tileType)
                {
                    amount++;
                }
            }

            return(amount >= minValue);
        }
Beispiel #13
0
 private void FindNearestNeighbors(Attributes[] testAttributes, Attributes tuner, int k)
 {
     foreach (Attributes trainingInstance in testAttributes)
     {
         if (trainingInstance.xy != tuner.xy)
         {
             Calculator tCalc = new Calculator(tuner.xy, trainingInstance.xy);
             Euclidaen.Add(new KeyValuePair <float, Attributes>(tCalc.getEuclidaen, trainingInstance));
             Chebyshev.Add(new KeyValuePair <float, Attributes>(tCalc.getChebyshev, trainingInstance));
             Manhattan.Add(new KeyValuePair <float, Attributes>(tCalc.getManhattan, trainingInstance));
         }
     }
     Euclidaen = Euclidaen.OrderBy(o => o.Key).Take(k).ToList();
     Chebyshev = Chebyshev.OrderBy(o => o.Key).Take(k).ToList();
     Manhattan = Manhattan.OrderBy(o => o.Key).Take(k).ToList();
 }
Beispiel #14
0
        public Player(Type bettingStrategy, int StartingFunds, int MinimumBetAmount)
        {
            this.PrimaryHand   = new Hand();
            this.SplitHand     = new Hand();
            this.Statistics    = new Stats();
            this.Funds         = StartingFunds;
            this.StartingFunds = StartingFunds;

            if (bettingStrategy == typeof(Manhattan))
            {
                BettingStrategy = new Manhattan(MinimumBetAmount);
            }
            else if (bettingStrategy == typeof(Martingale))
            {
                BettingStrategy = new Martingale(MinimumBetAmount);
            }
        }
Beispiel #15
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition center)
        {
            for (int d = 1; d <= radius; d++)
            {
                int rDamage = damage * (radius - d + 1) / radius;

                TilePosition[] tiles = Manhattan.GetTilesAtDistance(d);

                for (int i = 0; i < tiles.Length; i++)
                {
                    TilePosition p = center + tiles[i];

                    if (tileManager.IsValidTile(p))
                    {
                        if (tileManager.DamageTile(p, rDamage) == false)
                        {
                            if (setOnFire && tileManager.GetTileDefinition(tileManager.GetTileType(p)).burns)
                            {
                                tileManager.SetTileOnFire(p, true);
                            }
                        }
                    }
                }
            }

            if (setOnFire)
            {
                TilePosition[] tiles = Manhattan.GetTilesAtDistance(radius + 1);

                for (int i = 0; i < tiles.Length; i++)
                {
                    TilePosition p = center + tiles[i];

                    if (tileManager.IsValidTile(p))
                    {
                        if (setOnFire && tileManager.GetTileDefinition(tileManager.GetTileType(p)).burns)
                        {
                            tileManager.SetTileOnFire(p, true);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Util      util      = new Util();
            Manhattan manhattan = util.GetManhattanData();

            Console.WriteLine("*************************************************************");
            Console.WriteLine("1) Output all of the neighborhoods in this data list");
            util.OutputNeighborhood(manhattan);
            Console.WriteLine("*************************************************************");
            Console.WriteLine("2) Filtered out all the neighborhoods that do not have any names");
            util.FilterNoNameNeighborhood(manhattan);
            Console.WriteLine("*************************************************************");
            Console.WriteLine("3) Remove the Duplicates");
            util.RemoveDuplicates(manhattan);

            Console.WriteLine("*************************************************************");
            Console.WriteLine("4) Remove the Duplicates");
            Console.WriteLine("4) Filtered out all the neighborhoods that do not have any names");
            util.RemoveDuplicateAndNoNameNeighborhood(manhattan);

            Console.WriteLine("*************************************************************");
            Console.WriteLine("5) In LINQ");
            util.RewriteWithLINQ(manhattan);
        }
Beispiel #17
0
    /// <summary>
    ///   Solves the current routing problem.
    /// </summary>
    private void Solve(int number_of_orders, int number_of_vehicles)
    {
        Console.WriteLine("Creating model with " + number_of_orders +
                          " orders and " + number_of_vehicles + " vehicles.");
        // Finalizing model
        int number_of_locations = locations_.Length;

        RoutingModel model =
            new RoutingModel(number_of_locations, number_of_vehicles,
                             vehicle_starts_, vehicle_ends_);

        // Setting up dimensions
        const int      big_number         = 100000;
        NodeEvaluator2 manhattan_callback = new Manhattan(locations_, 1);

        model.AddDimension(
            manhattan_callback, big_number, big_number, false, "time");
        NodeEvaluator2 demand_callback = new Demand(order_demands_);

        model.AddDimension(demand_callback, 0, vehicle_capacity_, true, "capacity");

        // Setting up vehicles
        NodeEvaluator2[] cost_callbacks = new NodeEvaluator2[number_of_vehicles];
        for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle)
        {
            int            cost_coefficient        = vehicle_cost_coefficients_[vehicle];
            NodeEvaluator2 manhattan_cost_callback =
                new Manhattan(locations_, cost_coefficient);
            cost_callbacks[vehicle] = manhattan_cost_callback;
            model.SetVehicleCost(vehicle, manhattan_cost_callback);
            model.CumulVar(model.End(vehicle), "time").SetMax(
                vehicle_end_time_[vehicle]);
        }

        // Setting up orders
        for (int order = 0; order < number_of_orders; ++order)
        {
            model.CumulVar(order, "time").SetRange(order_time_windows_[order].start_,
                                                   order_time_windows_[order].end_);
            int[] orders = { order };
            model.AddDisjunction(orders, order_penalties_[order]);
        }

        // Solving
        RoutingSearchParameters search_parameters =
            RoutingModel.DefaultSearchParameters();

        search_parameters.FirstSolutionStrategy =
            FirstSolutionStrategy.Types.Value.AllUnperformed;

        Console.WriteLine("Search");
        Assignment solution = model.SolveWithParameters(search_parameters);

        //protect callbacks from the GC
        GC.KeepAlive(manhattan_callback);
        GC.KeepAlive(demand_callback);
        for (int cost_callback_index = 0; cost_callback_index < cost_callbacks.Length; cost_callback_index++)
        {
            GC.KeepAlive(cost_callbacks[cost_callback_index]);
        }

        if (solution != null)
        {
            String output = "Total cost: " + solution.ObjectiveValue() + "\n";
            // Dropped orders
            String dropped = "";
            for (int order = 0; order < number_of_orders; ++order)
            {
                if (solution.Value(model.NextVar(order)) == order)
                {
                    dropped += " " + order;
                }
            }
            if (dropped.Length > 0)
            {
                output += "Dropped orders:" + dropped + "\n";
            }
            // Routes
            for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle)
            {
                String route = "Vehicle " + vehicle + ": ";
                long   order = model.Start(vehicle);
                if (model.IsEnd(solution.Value(model.NextVar(order))))
                {
                    route += "Empty";
                }
                else
                {
                    for (;
                         !model.IsEnd(order);
                         order = solution.Value(model.NextVar(order)))
                    {
                        IntVar local_load = model.CumulVar(order, "capacity");
                        IntVar local_time = model.CumulVar(order, "time");
                        route += order + " Load(" + solution.Value(local_load) + ") " +
                                 "Time(" + solution.Min(local_time) + ", " +
                                 solution.Max(local_time) + ") -> ";
                    }
                    IntVar load = model.CumulVar(order, "capacity");
                    IntVar time = model.CumulVar(order, "time");
                    route += order + " Load(" + solution.Value(load) + ") " +
                             "Time(" + solution.Min(time) + ", " + solution.Max(time) + ")";
                }
                output += route + "\n";
            }
            Console.WriteLine(output);
        }
    }
Beispiel #18
0
  /// <summary>
  ///   Solves the current routing problem.
  /// </summary>
  private void Solve(int number_of_orders, int number_of_vehicles) {
    Console.WriteLine("Creating model with " + number_of_orders +
                      " orders and " + number_of_vehicles + " vehicles.");
    // Finalizing model
    int number_of_locations = locations_.Length;

    RoutingModel model =
        new RoutingModel(number_of_locations, number_of_vehicles,
                         vehicle_starts_, vehicle_ends_);

    // Setting up dimensions
    const int big_number = 100000;
    NodeEvaluator2 manhattan_callback = new Manhattan(locations_, 1);
    model.AddDimension(
        manhattan_callback, big_number, big_number, false, "time");
    NodeEvaluator2 demand_callback = new Demand(order_demands_);
    model.AddDimension(demand_callback, 0, vehicle_capacity_, true, "capacity");

    // Setting up vehicles
    for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle) {
      int cost_coefficient = vehicle_cost_coefficients_[vehicle];
      NodeEvaluator2 manhattan_cost_callback =
          new Manhattan(locations_, cost_coefficient);
      model.SetVehicleCost(vehicle, manhattan_cost_callback);
      model.CumulVar(model.End(vehicle), "time").SetMax(
          vehicle_end_time_[vehicle]);
    }

    // Setting up orders
    for (int order = 0; order < number_of_orders; ++order) {
      model.CumulVar(order, "time").SetRange(order_time_windows_[order].start_,
                                             order_time_windows_[order].end_);
      int[] orders = {order};
      model.AddDisjunction(orders, order_penalties_[order]);
    }

    // Solving
    RoutingSearchParameters search_parameters =
        RoutingModel.DefaultSearchParameters();
    search_parameters.FirstSolutionStrategy =
        FirstSolutionStrategy.Types.Value.ALL_UNPERFORMED;

    Console.WriteLine("Search");
    Assignment solution = model.SolveWithParameters(search_parameters);

    if (solution != null) {
      String output = "Total cost: " + solution.ObjectiveValue() + "\n";
      // Dropped orders
      String dropped = "";
      for (int order = 0; order < number_of_orders; ++order) {
        if (solution.Value(model.NextVar(order)) == order) {
          dropped += " " + order;
        }
      }
      if (dropped.Length > 0) {
        output += "Dropped orders:" + dropped + "\n";
      }
      // Routes
      for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle) {
        String route = "Vehicle " + vehicle + ": ";
        long order = model.Start(vehicle);
        if (model.IsEnd(solution.Value(model.NextVar(order)))) {
          route += "Empty";
        } else {
          for (;
               !model.IsEnd(order);
               order = solution.Value(model.NextVar(order))) {
            IntVar local_load = model.CumulVar(order, "capacity");
            IntVar local_time = model.CumulVar(order, "time");
            route += order + " Load(" + solution.Value(local_load) + ") " +
                "Time(" + solution.Min(local_time) + ", " +
                solution.Max(local_time) + ") -> ";
          }
          IntVar load = model.CumulVar(order, "capacity");
          IntVar time = model.CumulVar(order, "time");
          route += order + " Load(" + solution.Value(load) + ") " +
              "Time(" + solution.Min(time) + ", " + solution.Max(time) + ")";
        }
        output += route + "\n";
      }
      Console.WriteLine(output);
    }
  }
Beispiel #19
0
        static void Main(string[] args)
        {
            if (args.Length == 5)
            {
                GraphExplorer explorer     = null;
                IFinder       finder       = null;
                string        inputFile    = args[2];
                string        outputFile   = args[3];
                string        dataFile     = args[4];
                string        operations   = null;
                string        solutionPath = "solution.txt";
                IState        solutionState;
                byte[]        dimensions, root;
                (dimensions, root) = LoadInputFile(inputFile);
                if (File.Exists(solutionPath))
                {
                    byte[] solutionDimensions, state;
                    (solutionDimensions, state) = LoadInputFile(solutionPath);
                    solutionState = new NodeState(solutionDimensions, state);
                }
                else
                {
                    byte   limit         = (byte)(dimensions[0] * dimensions[1]);
                    byte[] solutionArray = new byte[limit];
                    for (byte i = 0; i < limit - 1; ++i)
                    {
                        solutionArray[i] = (byte)(i + 1);
                    }
                    solutionArray[limit - 1] = 0;
                    solutionState            = new NodeState(dimensions, solutionArray);
                }
                try
                {
                    switch (args[0])
                    {
                    case "bfs":
                        finder     = new BFS();
                        operations = args[1].ToLower();
                        break;

                    case "dfs":
                        finder     = new DFS();
                        operations = Reverse(args[1].ToLower());
                        break;

                    case "astr":
                        HeuristicProvider heuristicProvider = null;
                        switch (args[1])
                        {
                        case "manh":
                            heuristicProvider = new Manhattan(solutionState);
                            break;

                        case "hamm":
                            heuristicProvider = new Hamming(solutionState);
                            break;
                        }
                        operations = "lrud";
                        finder     = new AStar(heuristicProvider);
                        break;
                    }
                    if (Enumerable.SequenceEqual(dimensions, solutionState.Dimensions))
                    {
                        explorer = GraphExplorer.CreateGraphExplorer(dimensions,
                                                                     root, operations.ToCharArray(), finder);
                        explorer.TargetState = solutionState;
                    }
                    else
                    {
                        throw new NullReferenceException("root state and solution state have different dimensions");
                    }
                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine($"Wrong parameters format {Environment.NewLine}{e.Message}");
                }
                catch (FormatException e)
                {
                    Console.WriteLine($"Wrong input file format {Environment.NewLine}{e.Message}");
                }
                string solution = explorer.TraverseForSolution();
                WriteOutputFiles(outputFile, dataFile, solution, explorer);
            }
        }
Beispiel #20
0
    /// <summary>
    ///   Solves the current routing problem.
    /// </summary>
    private void Solve(int number_of_orders, int number_of_vehicles)
    {
        Console.WriteLine("Creating model with " + number_of_orders + " orders and " + number_of_vehicles +
                          " vehicles.");
        // Finalizing model
        int number_of_locations = locations_.Length;

        RoutingIndexManager manager =
            new RoutingIndexManager(number_of_locations, number_of_vehicles, vehicle_starts_, vehicle_ends_);
        RoutingModel model = new RoutingModel(manager);

        // Setting up dimensions
        const int big_number         = 100000;
        Manhattan manhattan_callback = new Manhattan(manager, locations_, 1);

        model.AddDimension(model.RegisterTransitCallback(manhattan_callback.Call), big_number, big_number, false,
                           "time");
        RoutingDimension time_dimension = model.GetDimensionOrDie("time");

        Demand demand_callback = new Demand(manager, order_demands_);

        model.AddDimension(model.RegisterUnaryTransitCallback(demand_callback.Call), 0, vehicle_capacity_, true,
                           "capacity");
        RoutingDimension capacity_dimension = model.GetDimensionOrDie("capacity");

        // Setting up vehicles
        Manhattan[] cost_callbacks = new Manhattan[number_of_vehicles];
        for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle)
        {
            int       cost_coefficient        = vehicle_cost_coefficients_[vehicle];
            Manhattan manhattan_cost_callback = new Manhattan(manager, locations_, cost_coefficient);
            cost_callbacks[vehicle] = manhattan_cost_callback;
            int manhattan_cost_index = model.RegisterTransitCallback(manhattan_cost_callback.Call);
            model.SetArcCostEvaluatorOfVehicle(manhattan_cost_index, vehicle);
            time_dimension.CumulVar(model.End(vehicle)).SetMax(vehicle_end_time_[vehicle]);
        }

        // Setting up orders
        for (int order = 0; order < number_of_orders; ++order)
        {
            time_dimension.CumulVar(order).SetRange(order_time_windows_[order].start_, order_time_windows_[order].end_);
            long[] orders = { manager.NodeToIndex(order) };
            model.AddDisjunction(orders, order_penalties_[order]);
        }

        // Solving
        RoutingSearchParameters search_parameters =
            operations_research_constraint_solver.DefaultRoutingSearchParameters();

        search_parameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.AllUnperformed;

        Console.WriteLine("Search...");
        Assignment solution = model.SolveWithParameters(search_parameters);

        if (solution != null)
        {
            String output = "Total cost: " + solution.ObjectiveValue() + "\n";
            // Dropped orders
            String dropped = "";
            for (int order = 0; order < number_of_orders; ++order)
            {
                if (solution.Value(model.NextVar(order)) == order)
                {
                    dropped += " " + order;
                }
            }
            if (dropped.Length > 0)
            {
                output += "Dropped orders:" + dropped + "\n";
            }
            // Routes
            for (int vehicle = 0; vehicle < number_of_vehicles; ++vehicle)
            {
                String route = "Vehicle " + vehicle + ": ";
                long   order = model.Start(vehicle);
                if (model.IsEnd(solution.Value(model.NextVar(order))))
                {
                    route += "Empty";
                }
                else
                {
                    for (; !model.IsEnd(order); order = solution.Value(model.NextVar(order)))
                    {
                        IntVar local_load = capacity_dimension.CumulVar(order);
                        IntVar local_time = time_dimension.CumulVar(order);
                        route += order + " Load(" + solution.Value(local_load) + ") " + "Time(" +
                                 solution.Min(local_time) + ", " + solution.Max(local_time) + ") -> ";
                    }
                    IntVar load = capacity_dimension.CumulVar(order);
                    IntVar time = time_dimension.CumulVar(order);
                    route += order + " Load(" + solution.Value(load) + ") " + "Time(" + solution.Min(time) + ", " +
                             solution.Max(time) + ")";
                }
                output += route + "\n";
            }
            Console.WriteLine(output);
        }
    }
Beispiel #21
0
        public static Vector2 UnityToCoord(Vector3 v)
        {
            Vector2d c = Manhattan.WorldToGeoPosition(v);

            return(new Vector2((float)c.x, (float)c.y));
        }
Beispiel #22
0
        static void JsonConversion()
        {
            string path = "../../../../data.json";
            string text = "";

            using (StreamReader sr = File.OpenText(path))
            {
                text = sr.ReadToEnd();
            }

            Manhattan data = JsonConvert.DeserializeObject <Manhattan>(text);

            var boroughs = data.Features.Select(x => x).Select(x => x.Properties).Select(x => x.Neighborhood);

            var allHoods = from hood in boroughs
                           select hood;

            Console.WriteLine("1. All neighborhoods in the data list: ");

            foreach (var item in allHoods)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("2. Filter neighborhoods with no name: ");

            var removeNoName = from hood in allHoods
                               where hood != ""
                               select hood;

            foreach (var item in removeNoName)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("3. Remove duplicate hoods: ");

            var removeDup = (from hood in allHoods
                             orderby hood
                             select hood).Distinct();

            foreach (var item in removeDup)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("4. Now all in one query: ");

            var singleQuery = (from hood in boroughs
                               orderby hood
                               where hood != ""
                               select hood).Distinct();

            foreach (var item in singleQuery)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("5. Now with a lambda: ");

            var lambda = allHoods.Where(hood => hood != "").Distinct().OrderBy(hood => hood);

            foreach (var item in lambda)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #23
0
        private void Propagate(TileManager tileManager, Tile tile, TilePosition pos, int level)
        {
            TilePosition posBelow          = pos + new TilePosition(0, -1, 0);
            bool         belowIsSameLiquid = tileManager.IsValidTile(posBelow) && tileManager.GetTileType(posBelow) == tile.tileType;

            if (tileManager.IsValidTile(posBelow) && (tileManager.GetTileType(posBelow) == TileDefinition.EMPTY_TILE_TYPE) || belowIsSameLiquid)
            {
                if (belowIsSameLiquid == false)
                {
                    tileManager.SetTileType(posBelow, tile.tileType);
                    tileManager.SetTileExtraData(posBelow, 1);
                }
            }
            else
            {
                if (level < maxLevel)
                {
                    TilePosition[] nearDirection = new TilePosition[4];

                    int[] nearDistance = new int[] { maxLevel, maxLevel, maxLevel, maxLevel };

                    FindFall(new TilePosition(1, 0, 0), tileManager, tile, pos, ref nearDirection[0], ref nearDistance[0]);
                    FindFall(new TilePosition(-1, 0, 0), tileManager, tile, pos, ref nearDirection[1], ref nearDistance[1]);
                    FindFall(new TilePosition(0, 0, 1), tileManager, tile, pos, ref nearDirection[2], ref nearDistance[2]);
                    FindFall(new TilePosition(0, 0, -1), tileManager, tile, pos, ref nearDirection[3], ref nearDistance[3]);

                    int minNearDistance = Math.Min(Math.Min(Math.Min(nearDistance[0], nearDistance[1]), nearDistance[2]), nearDistance[3]);

                    if (minNearDistance != maxLevel)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (nearDistance[i] == minNearDistance)
                            {
                                TilePosition posNear = pos + nearDirection[i];

                                if (tileManager.IsValidTile(posNear) && tileManager.GetTileType(posNear) == TileDefinition.EMPTY_TILE_TYPE)
                                {
                                    TilePosition posNearBelow          = posNear + new TilePosition(0, -1, 0);
                                    bool         nearBelowIsSameLiquid = tileManager.IsValidTile(posNearBelow) && tileManager.GetTileType(posNearBelow) == tile.tileType;

                                    if (nearBelowIsSameLiquid == false || belowIsSameLiquid == false)
                                    {
                                        tileManager.SetTileType(posNear, tile.tileType);
                                        tileManager.SetTileExtraData(posNear, (byte)(level + 1));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (TilePosition deltaPos in Manhattan.GetTilesAtDistance(1))
                        {
                            if (deltaPos.y == 0)
                            {
                                TilePosition posNear = pos + deltaPos;
                                if (tileManager.IsValidTile(posNear) && tileManager.GetTileType(posNear) == TileDefinition.EMPTY_TILE_TYPE)
                                {
                                    TilePosition posNearBelow          = posNear + new TilePosition(0, -1, 0);
                                    bool         nearBelowIsSameLiquid = tileManager.IsValidTile(posNearBelow) && tileManager.GetTileType(posNearBelow) == tile.tileType;

                                    if (nearBelowIsSameLiquid == false || belowIsSameLiquid == false)
                                    {
                                        tileManager.SetTileType(posNear, tile.tileType);
                                        tileManager.SetTileExtraData(posNear, (byte)(level + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }