コード例 #1
0
ファイル: CommandDispatch.cs プロジェクト: fburel/HashCode
        /// <summary>
        /// Create a monoProduct order and update the inventory
        /// </summary>
        /// <param name="warehouse">Warehouse.</param>
        /// <param name="cell">Cell.</param>
        /// <param name="type">Type.</param>
        /// <param name="qtt">Qtt.</param>
        void PlaceOrder(WareHouse warehouse, Cell cell, ProductType type, int qtt)
        {
            var detail = new Dictionary<ProductType, int>();
            detail.Add(type, qtt);

            Order order = new Order(detail, cell);

            Affect(order, warehouse);

            var inv = Inventories [warehouse];

            var value = inv [type];

            value -= qtt;

            if(value == 0)
            {
                inv.Remove(type);
            }
            else
            {
                inv [type] = value;
            }
        }
コード例 #2
0
ファイル: Order.cs プロジェクト: fburel/HashCode
 public Order( Dictionary<ProductType,int> products, Cell destination)
 {
     Products = products;
     Destination = destination;
 }
コード例 #3
0
ファイル: CommandDispatch.cs プロジェクト: fburel/HashCode
 /// <summary>
 /// Orders the ware houses by distance from the given cell
 /// </summary>
 /// <returns>The ware houses by distance.</returns>
 /// <param name="cell">Cell.</param>
 List<WareHouse> OrderWareHousesByDistance(Cell cell)
 {
     return Inventories.Keys.ToList().OrderBy(wh => cell.Distance(wh.Position)).ToList();
 }
コード例 #4
0
ファイル: ProblemFactory.cs プロジェクト: fburel/HashCode
        /// <summary>
        /// Creates from file.
        /// </summary>
        /// <returns>The from file.</returns>
        /// <param name="file">File.</param>
        public Problem CreateFromFile(HashCodeFile file)
        {
            // Problem data
            List<WareHouse> wareHouses = new List<WareHouse>();
            List<Order> orders = new List<Order>();
            Map map = new Map();
            int numberOfTurns= 0;
            List<ProductType> productTypes = new List<ProductType>();
            List<Drone> drones = new List<Drone>();

            int lineCount = 0;
            int nbWarehouse = 0;
            int currentWarehouse = 0;
            int nbOrder = 0;
            int currentOrder = 0;

            // Parse the file
            using (StreamReader sr = file.OpenStream())
            {
                string line = "";
                while((line = sr.ReadLine()) != null)
                {

                    if (lineCount == 0) {

                        List<string> data = line.Split (' ').ToList();

                        var numberOfRow = data [0];
                        var numberOfColumn = data [1];
                        var numberOfDrones = data[2];
                        int.TryParse(data[3], out numberOfTurns);
                        int maxWeightPerDrone = int.Parse(data [4]);

                        map = new Map (numberOfRow , numberOfColumn);

                        for (int i = 0; i < int.Parse(numberOfDrones); i++) {
                            drones.Add (new Drone (maxWeightPerDrone));
                        }
                    }

                    else if (lineCount == 1)
                    {
                        // number of product type.
                    }

                    else if (lineCount == 2)
                    {
                        List<string> datas = line.Split (' ').ToList ();
                        for (int i = 0; i < datas.Count; i++) {
                            productTypes.Add (new ProductType (i, int.Parse (datas [i])));
                        }
                    }

                    else if (lineCount == 3) {

                        nbWarehouse = int.Parse (line);
                    }

                    else if (lineCount <= 3 + (nbWarehouse * 2)) {
                        List<string> datas = new List<string> ();
                        datas.Add (line);
                        datas.Add (sr.ReadLine());
                        lineCount++;

                        var rowColumnData = datas [0];

                        string[] d = rowColumnData.Split (' ');
                        int row = int.Parse(d [0]);
                        int column = int.Parse(d [1]);

                        Cell position = new Cell(row, column);

                        var productInventory = new Dictionary<ProductType, int>();

                        List<string> quantitities = datas[1].Split(' ').ToList();

                        for (int pdtCode = 0 ; pdtCode < quantitities.Count; pdtCode++) {

                            var qtt = int.Parse(quantitities[pdtCode]);
                            var productType = productTypes [pdtCode];

                            productInventory.Add(productType, qtt);

                            pdtCode++;

                        }

                        wareHouses.Add (new WareHouse(productInventory, position, currentWarehouse));
                    }

                    else if (lineCount == 3 + (nbWarehouse * 2) + 1) {
                        nbOrder = int.Parse (line);
                    }

                    else {
                        List<string> datas = new List<string> ();
                        datas.Add (line);
                        datas.Add (sr.ReadLine());
                        lineCount++;
                        datas.Add (sr.ReadLine());
                        lineCount++;

                        var rowColumnData = datas [0];

                        string[] d = rowColumnData.Split (' ');
                        int row = int.Parse(d [0]);
                        int column = int.Parse(d [1]);

                        Cell destination = new Cell(row, column);

                        Dictionary<ProductType, int> products = new Dictionary<ProductType, int>();

                        string[] productsData = datas [2].Split (' ');

                        for (int i = 0; i < productsData.Length; i++)
                        {
                            int qty = int.Parse (productsData [i]);
                            if (qty > 0)
                            {
                                products.Add (productTypes [i], qty);
                            }
                        }

                        orders.Add(new Order(products, destination));

                    }
                    lineCount++;
                }

                sr.Close();
                sr.Dispose();
            }

            var problem = new Problem(
                wareHouses,
                orders,
                map,
                numberOfTurns,
                productTypes,
                drones
            );

            problem.Name = file.Name;

            return problem;
        }
コード例 #5
0
ファイル: Drone.cs プロジェクト: fburel/HashCode
 public Drone(int max)
 {
     Position = new Cell (0, 0);
     MaxWeight = max;
 }
コード例 #6
0
ファイル: Drone.cs プロジェクト: fburel/HashCode
 public void MoveTo(Cell c)
 {
     TotalTurn += (int)Math.Ceiling (Position.Distance (c));
     Position = c;
 }
コード例 #7
0
ファイル: WareHouse.cs プロジェクト: fburel/HashCode
 public WareHouse(Dictionary<ProductType, int> productInventory, Cell position, int index)
 {
     Products = productInventory;
     Position = position;
     Idx = index;
 }
コード例 #8
0
ファイル: Cell.cs プロジェクト: fburel/HashCode
 public double Distance(Cell c)
 {
     return Math.Sqrt (Math.Pow (this.Column - c.Column, 2) + Math.Pow (this.Row - c.Row, 2));
 }