Created
February 11, 2016 19:53
-
-
Save ishmaelmakitla/5551deaa0bc2faa1cc0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package za.co.pta.gdg.hashcode.delivery; | |
| import java.io.BufferedReader; | |
| import java.io.FileReader; | |
| public class DeliveryCommandProcessor { | |
| //rows | |
| int rows; | |
| int columns; | |
| //number of drones | |
| int drones = -1; | |
| //number of customers | |
| int customers = -1; | |
| //number of warehouses | |
| int warehouses = -1; | |
| //number of orders | |
| int orders = -1; | |
| //number of available products | |
| int products = -1; | |
| //array of products | |
| int[][] productWeightPerType = null; | |
| //number of product types | |
| int productTypes = -1; | |
| int maximumPayload = -1; | |
| int maxTurns = -1; | |
| int[][] map = null; | |
| static final int ROWS_INDEX=0; | |
| static final int COLS_INDEX=1; | |
| static final int DRONES_INDEX=2; | |
| static final int TURNS_INDEX = 3; | |
| static final int PAYLOAD_INDEX=4; | |
| static final int INIT_LINE = 0; | |
| static final int PRODUCTS_TYPES_COUNT_LINE = 1; //second line in the file | |
| static final int PRODUCT_TYPES_WEIGHTS_LINE = 2; //3RD | |
| static final int WAREHOUSES_COUNT_LINE =3; //4TH | |
| static final int FIRST_WAREHOUSE_LINE = 4; //5TH location of first | |
| static final int WAREHOUSE_INVENTORY_LINE = 5; //6TH products-count of each type | |
| static final int DISTANCE_IN_LINES_BETWEEN_HW = 2; | |
| public DeliveryCommandProcessor(){ | |
| } | |
| public void fromFile(String filePath){ | |
| try{ | |
| //do something | |
| FileReader fr = new FileReader(filePath); | |
| BufferedReader br = new BufferedReader(fr); | |
| String line; | |
| int lineCounter = 0; | |
| while ((line = br.readLine()) != null) { | |
| if(lineCounter == 0){ | |
| //first line - init | |
| System.out.println(line); | |
| String[] values = line.split(" "); | |
| rows = Integer.valueOf(values[ROWS_INDEX]); | |
| columns = Integer.valueOf(values[COLS_INDEX]); | |
| drones = Integer.valueOf(values[DRONES_INDEX]); | |
| maxTurns = Integer.valueOf(values[TURNS_INDEX]); | |
| maximumPayload = Integer.valueOf(values[PAYLOAD_INDEX]); | |
| System.out.println("Drones = "+drones); | |
| } | |
| //are we looking at the products types line? | |
| else if (lineCounter == PRODUCTS_TYPES_COUNT_LINE){ | |
| productTypes = Integer.valueOf(line.trim()); | |
| System.out.println("Number of Product Types = "+productTypes); | |
| } | |
| else if(lineCounter == PRODUCT_TYPES_WEIGHTS_LINE){ | |
| String[] weights = line.trim().split(" "); | |
| productWeightPerType = new int[productTypes][weights.length]; | |
| //loop through the product types and assign weights to each | |
| for(int x=0; x< productTypes; x++){ | |
| for(int y=0; y < weights.length; y++){ | |
| productWeightPerType[x][y] = Integer.valueOf(weights[y]); | |
| } | |
| } | |
| } | |
| else if (lineCounter == WAREHOUSES_COUNT_LINE){ | |
| warehouses = Integer.valueOf(line.trim()); | |
| System.out.println("Number of Ware Houses = "+warehouses); | |
| } | |
| else if(lineCounter < (FIRST_WAREHOUSE_LINE *warehouses)){ | |
| //we have seen all ware houses | |
| } | |
| lineCounter +=1; | |
| } | |
| } | |
| catch(Exception e){ | |
| e.printStackTrace(); | |
| } | |
| } | |
| private void processInputFile(){ | |
| } | |
| /** | |
| * Move: Moves the specified number of items of the specified product type from a warehouse to the | |
| drone’s inventory. If the drone isn’t at the warehouse it will fly there using the shortest path before | |
| loading the product items. The requested number of items of the specified product type must be | |
| available in the warehouse. The total weight of the items in the drone’s inventory after the load | |
| cannot be bigger than the drone’s maximum load. | |
| */ | |
| /** | |
| * Delivers the specified number of items of the specified product type to a customer. If the | |
| drone isn’t at the destination it will fly there using the shortest path before delivering the product | |
| items. The drone must have the requested number of items of the specified product type in its | |
| inventory. | |
| */ | |
| /** | |
| * Unload: Moves the specified number of items of the specified product type from drone’s inventory to | |
| a warehouse. If the drone isn’t at the warehouse it will fly there using the shortest path before | |
| unloading the product items. The drone must have the requested number of items of the specified | |
| product type in its inventory. | |
| */ | |
| /* | |
| * Wait : Waits the specified number of turns in the drone's current location. | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment