diff --git a/Automail/.idea/.gitignore b/Automail/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26d33521af10bcc7fd8cea344038eaaeb78d0ef5 --- /dev/null +++ b/Automail/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Automail/.idea/misc.xml b/Automail/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..1f35e349b71d88e0478dd31f4d64e8d013e704e9 --- /dev/null +++ b/Automail/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="JavaSE-11" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/classes" /> + </component> +</project> \ No newline at end of file diff --git a/Automail/.idea/modules.xml b/Automail/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..7ca9c9c20e42842e911dd1daf05862f5b784c5bf --- /dev/null +++ b/Automail/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/Automail.iml" filepath="$PROJECT_DIR$/Automail.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/Automail/.idea/vcs.xml b/Automail/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ b/Automail/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/Automail/Automail.iml b/Automail/Automail.iml new file mode 100644 index 0000000000000000000000000000000000000000..1666f240b5d6887e3a79520f84f7f3d520939ecb --- /dev/null +++ b/Automail/Automail.iml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="EclipseModuleManager"> + <libelement value="jar://$MODULE_DIR$/WifiModem.jar!/" /> + <src_description expected_position="0"> + <src_folder value="file://$MODULE_DIR$/src" expected_position="0" /> + </src_description> + </component> + <component name="NewModuleRootManager"> + <output url="file://$MODULE_DIR$/bin" /> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="jdk" jdkName="JavaSE-11" jdkType="JavaSDK" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module-library" exported=""> + <library name="WifiModem.jar"> + <CLASSES> + <root url="jar://$MODULE_DIR$/WifiModem.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="file://$MODULE_DIR$/src" /> + </SOURCES> + </library> + </orderEntry> + </component> +</module> \ No newline at end of file diff --git a/Automail/automail.properties b/Automail/automail.properties index a2e6ec2743c3edb3a111da0b9eea131acbc5988a..56172357a52a385ed7e6a225ee94a381c59cc64b 100644 --- a/Automail/automail.properties +++ b/Automail/automail.properties @@ -11,5 +11,5 @@ Mail_Max_Weight=2000 Mail_Receving_Length=120 # Robots Robots=3 -ChargeThreshold=0 +ChargeThreshold=10 CommercialDisplay=false diff --git a/Automail/bin/automail/Automail.class b/Automail/bin/automail/Automail.class index 62843ad187fb228ee40a5d26040d3cea93fada0d..2ab9fd12dd68e38ea997f7231794a868ddfcc096 100644 Binary files a/Automail/bin/automail/Automail.class and b/Automail/bin/automail/Automail.class differ diff --git a/Automail/bin/automail/MailItem.class b/Automail/bin/automail/MailItem.class index a7c448693495b3db5f22c336e5b7ff348c696be8..b7c555714d8f522def3fff93345f62e49c16cd2d 100644 Binary files a/Automail/bin/automail/MailItem.class and b/Automail/bin/automail/MailItem.class differ diff --git a/Automail/bin/automail/MailPool$Item.class b/Automail/bin/automail/MailPool$Item.class index 3d1e38b51eec6c8c4e1491fb8dbf424bf38c1fc0..57d68b1c09374ced969c23f22b50f4af1f8b375f 100644 Binary files a/Automail/bin/automail/MailPool$Item.class and b/Automail/bin/automail/MailPool$Item.class differ diff --git a/Automail/bin/automail/MailPool$ItemComparator.class b/Automail/bin/automail/MailPool$ItemComparator.class index c805875b7dcc0b6cb1b79f61cc9a1ab251999238..14d2812a6cf864e01e29eb8416c4341994357ec6 100644 Binary files a/Automail/bin/automail/MailPool$ItemComparator.class and b/Automail/bin/automail/MailPool$ItemComparator.class differ diff --git a/Automail/bin/automail/MailPool.class b/Automail/bin/automail/MailPool.class index da791cb42c34ef784d112335c4fd4a04fff77586..ddfd65a1ce90d47af19fafdac9c39650162df53d 100644 Binary files a/Automail/bin/automail/MailPool.class and b/Automail/bin/automail/MailPool.class differ diff --git a/Automail/bin/automail/Robot$1.class b/Automail/bin/automail/Robot$1.class new file mode 100644 index 0000000000000000000000000000000000000000..7aae8d8082ee8d1157b786a2ce3cde5336bd61cc Binary files /dev/null and b/Automail/bin/automail/Robot$1.class differ diff --git a/Automail/bin/automail/Robot$RobotState.class b/Automail/bin/automail/Robot$RobotState.class index 7a06471d0faeef4b50a6c1f2aab1f1b56ddc5cb7..79ed49a922fca7ef09e6c9aeb23337d1bbb93867 100644 Binary files a/Automail/bin/automail/Robot$RobotState.class and b/Automail/bin/automail/Robot$RobotState.class differ diff --git a/Automail/bin/automail/Robot.class b/Automail/bin/automail/Robot.class index 54873ff5cbd973888165384dff98f9f32f788e79..825c0cc9e0fe5d268e1f312607b96f0f717024aa 100644 Binary files a/Automail/bin/automail/Robot.class and b/Automail/bin/automail/Robot.class differ diff --git a/Automail/bin/exceptions/ExcessiveDeliveryException.class b/Automail/bin/exceptions/ExcessiveDeliveryException.class index 0d6e88683faf2307f1bb3fe254dd791494a2bdd9..2d57bb828512782c52fea814929fc73bba340786 100644 Binary files a/Automail/bin/exceptions/ExcessiveDeliveryException.class and b/Automail/bin/exceptions/ExcessiveDeliveryException.class differ diff --git a/Automail/bin/exceptions/ItemTooHeavyException.class b/Automail/bin/exceptions/ItemTooHeavyException.class index 7d360f113a93bcd944eb5bc9d8d26901f2713688..9a23918393c07e719e97263677bc4f631a42d0e5 100644 Binary files a/Automail/bin/exceptions/ItemTooHeavyException.class and b/Automail/bin/exceptions/ItemTooHeavyException.class differ diff --git a/Automail/bin/exceptions/MailAlreadyDeliveredException.class b/Automail/bin/exceptions/MailAlreadyDeliveredException.class index 85bf1e255d75951054ad85d843a11d84a881c709..be0f061abc1867b8c62d6d1b3edee5e5a55e8c4b 100644 Binary files a/Automail/bin/exceptions/MailAlreadyDeliveredException.class and b/Automail/bin/exceptions/MailAlreadyDeliveredException.class differ diff --git a/Automail/bin/simulation/Building.class b/Automail/bin/simulation/Building.class index 6678acdcf8ae93daeab7e80009725a553edc9b4c..b77dcadb59fb892c461c5ef9854525dcff1e5dcc 100644 Binary files a/Automail/bin/simulation/Building.class and b/Automail/bin/simulation/Building.class differ diff --git a/Automail/bin/simulation/Clock.class b/Automail/bin/simulation/Clock.class index 6c169fe5d8969d75545edc3b0f1e2cb80c815fe2..bfdc433ab563649d473f713a183f9dbb0359953a 100644 Binary files a/Automail/bin/simulation/Clock.class and b/Automail/bin/simulation/Clock.class differ diff --git a/Automail/bin/simulation/IMailDelivery.class b/Automail/bin/simulation/IMailDelivery.class index bb88966905293af8ebdb81a32c69b4fa75f977ce..2100e1d2d509704156e1a1609a3b874d9de53c76 100644 Binary files a/Automail/bin/simulation/IMailDelivery.class and b/Automail/bin/simulation/IMailDelivery.class differ diff --git a/Automail/bin/simulation/MailGenerator.class b/Automail/bin/simulation/MailGenerator.class index 5badad3f6cf87e7380200279401e7f23cb2ae704..b1ea86bcd7abaf903e3bc9867d27cd32f00b5c63 100644 Binary files a/Automail/bin/simulation/MailGenerator.class and b/Automail/bin/simulation/MailGenerator.class differ diff --git a/Automail/bin/simulation/Simulation$ReportDelivery.class b/Automail/bin/simulation/Simulation$ReportDelivery.class index 01d9be852ee89259d1d5038192494a2d315fb797..1f7a608a2f0bf3e55925b40dbe03673c8fb0c9e5 100644 Binary files a/Automail/bin/simulation/Simulation$ReportDelivery.class and b/Automail/bin/simulation/Simulation$ReportDelivery.class differ diff --git a/Automail/bin/simulation/Simulation.class b/Automail/bin/simulation/Simulation.class index a783d4b0ac2713bda772c7af90b274741cafaf18..b673babb39964713c20b90ed6e891a683f424068 100644 Binary files a/Automail/bin/simulation/Simulation.class and b/Automail/bin/simulation/Simulation.class differ diff --git a/Automail/src/automail/MailItem.java b/Automail/src/automail/MailItem.java index 785dcfe4be293777f50fd122018a7fb169ecf643..2bdf9f2f8531b4494d96f326b8dd21cf4e3a2edc 100644 --- a/Automail/src/automail/MailItem.java +++ b/Automail/src/automail/MailItem.java @@ -19,6 +19,8 @@ public class MailItem { /** The weight in grams of the mail item */ protected final int weight; + private double serviceFee; + /** * Constructor for a MailItem * @param dest_floor the destination floor intended for this mail item @@ -32,6 +34,10 @@ public class MailItem { this.weight = weight; } + public void setServiceFee(double serviceFee){ + this.serviceFee = serviceFee; + } + @Override public String toString(){ return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d", id, arrival_time, destination_floor, weight); diff --git a/Automail/src/automail/MailPool.java b/Automail/src/automail/MailPool.java index b4ed25be753be943a678df91934c92edb6e4f49e..7977178aa28fece927ce960c9ab4011a86bc620b 100644 --- a/Automail/src/automail/MailPool.java +++ b/Automail/src/automail/MailPool.java @@ -1,11 +1,12 @@ package automail; -import java.util.LinkedList; +import exceptions.ItemTooHeavyException; +import simulation.Building; + import java.util.Comparator; +import java.util.LinkedList; import java.util.ListIterator; -import exceptions.ItemTooHeavyException; - /** * addToPool is called when there are mail items newly arrived at the building to add to the MailPool or * if a robot returns with some undelivered items - these are added back to the MailPool. @@ -13,9 +14,10 @@ import exceptions.ItemTooHeavyException; * */ public class MailPool { - private class Item { int destination; + double charge; + boolean isNewItem = true; MailItem mailItem; // Use stable sort to keep arrival time relative positions @@ -24,7 +26,7 @@ public class MailPool { this.mailItem = mailItem; } } - + public class ItemComparator implements Comparator<Item> { @Override public int compare(Item i1, Item i2) { @@ -56,9 +58,55 @@ public class MailPool { pool.add(item); pool.sort(new ItemComparator()); } - - - + + public double calculateCharge(int itemIndex, double serviceFee, double activityUnitPrice, double markupPercentage){ + double robotsMovement = 5.0D; + double remoteLookup = 0.1D; + int destination = pool.get(itemIndex).destination; + double activityUnits = ((destination - Building.MAILROOM_LOCATION) * robotsMovement) + remoteLookup; + double activityCost = activityUnits * activityUnitPrice; + double charge = (activityCost + serviceFee) * (1 + markupPercentage); + return charge; + } + + public void setItemCharge(int itemIndex, double charge){ + Item item = new Item(pool.get(itemIndex).mailItem); + item.charge = charge; + item.isNewItem = false; + pool.set(itemIndex, item); + } + + public void getItemInfo(int iii){ + System.out.println("New Item ID: " + pool.get(iii).mailItem.id + ", Item Charge: " + String.valueOf(pool.get(iii).charge)); + } + + public boolean isNewItem(int itemIndex){return pool.get(itemIndex).isNewItem;} + + public int getItemDestination(int itemIndex){ + return pool.get(itemIndex).destination; + } + + public int getPoolSize(){ + return pool.size(); + } + + public void sortPriorityMailItems(double chargeThreshold){ + LinkedList<Item> priorityPool = new LinkedList<>(); + ListIterator<Item> poolIterator = pool.listIterator(); + while (poolIterator.hasNext()){ + Item item = poolIterator.next(); + if(item.charge > chargeThreshold){ + priorityPool.addFirst(item); + poolIterator.remove(); + } + } + ListIterator<Item> priorityPoolIterator = priorityPool.listIterator(); + while (priorityPoolIterator.hasNext()){ + pool.addFirst(priorityPoolIterator.next()); + priorityPoolIterator.remove(); + } + } + /** * load up any waiting robots with mailItems, if any. */ diff --git a/Automail/src/automail/Robot.java b/Automail/src/automail/Robot.java index 4867889dfc5b23b64bcbef7a106e541aa78737b2..ff066165a2608fe944268beeae2596be77659d47 100644 --- a/Automail/src/automail/Robot.java +++ b/Automail/src/automail/Robot.java @@ -22,7 +22,6 @@ public class Robot { private int destination_floor; private MailPool mailPool; private boolean receivedDispatch; - private MailItem deliveryItem = null; private MailItem tube = null; @@ -173,4 +172,5 @@ public class Robot { if (tube.weight > INDIVIDUAL_MAX_WEIGHT) throw new ItemTooHeavyException(); } + } diff --git a/Automail/src/simulation/MailGenerator.java b/Automail/src/simulation/MailGenerator.java index 17a4a15dab3522c6d84c4b46793ca81a81970897..5b5acbe60c64e7b0bbfad1204d21ba6fcb250527 100644 --- a/Automail/src/simulation/MailGenerator.java +++ b/Automail/src/simulation/MailGenerator.java @@ -1,10 +1,13 @@ package simulation; -import java.util.*; - import automail.MailItem; import automail.MailPool; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + /** * This class generates the mail */ @@ -117,6 +120,10 @@ public class MailGenerator { } } + + public void setServiceFee(){ + + } /** * Given the clock time, put the generated mails into the mailPool. diff --git a/Automail/src/simulation/Simulation.java b/Automail/src/simulation/Simulation.java index 39c65fb7be1690d958cde42c859c8523b4a3ba5d..1dea0886e81f313ccc2fbc33f240cd85ade4425e 100644 --- a/Automail/src/simulation/Simulation.java +++ b/Automail/src/simulation/Simulation.java @@ -1,20 +1,16 @@ package simulation; +import automail.Automail; +import automail.MailItem; +import automail.MailPool; +import com.unimelb.swen30006.wifimodem.WifiModem; import exceptions.ExcessiveDeliveryException; import exceptions.ItemTooHeavyException; import exceptions.MailAlreadyDeliveredException; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; - -import com.unimelb.swen30006.wifimodem.WifiModem; - -import automail.Automail; -import automail.MailItem; -import automail.MailPool; +import java.util.*; /** * This class simulates the behaviour of AutoMail @@ -23,6 +19,8 @@ public class Simulation { private static int NUM_ROBOTS; private static double CHARGE_THRESHOLD; private static boolean CHARGE_DISPLAY; + private static double ACTIVITY_UNIT_PRICE; + private static double MARKUP_PERCENTAGE; /** Constant for the mail generator */ private static int MAIL_TO_CREATE; @@ -68,7 +66,6 @@ public class Simulation { } catch (Exception mException) { mException.printStackTrace(); } - /** * This code section is for running a simulation */ @@ -76,12 +73,26 @@ public class Simulation { MailPool mailPool = new MailPool(NUM_ROBOTS); Automail automail = new Automail(mailPool, new ReportDelivery(), NUM_ROBOTS); MailGenerator mailGenerator = new MailGenerator(MAIL_TO_CREATE, MAIL_MAX_WEIGHT, mailPool, seedMap); - /** Generate all the mails */ mailGenerator.generateAllMail(); while(MAIL_DELIVERED.size() != mailGenerator.MAIL_TO_CREATE) { // System.out.printf("Delivered: %4d; Created: %4d%n", MAIL_DELIVERED.size(), mailGenerator.MAIL_TO_CREATE); mailGenerator.addToMailPool(); + if(CHARGE_DISPLAY){ + int poolSize = mailPool.getPoolSize(); + for(int i=0; i<poolSize; i++){ + if(mailPool.isNewItem(i)) { + int destination = mailPool.getItemDestination(i); + double serviceFee = wModem.forwardCallToAPI_LookupPrice(destination); + double charge = mailPool.calculateCharge(i, serviceFee, ACTIVITY_UNIT_PRICE, MARKUP_PERCENTAGE); + mailPool.setItemCharge(i, charge); + mailPool.getItemInfo(i); + } + } + if(CHARGE_THRESHOLD != 0){ + mailPool.sortPriorityMailItems(CHARGE_THRESHOLD); + } + } try { automail.mailPool.loadItemsToRobot(); for (int i=0; i < NUM_ROBOTS; i++) { @@ -105,7 +116,9 @@ public class Simulation { automailProperties.setProperty("Floors", "10"); automailProperties.setProperty("Mail_to_Create", "80"); automailProperties.setProperty("ChargeThreshold", "0"); - automailProperties.setProperty("ChargeDisplay", "false"); + automailProperties.setProperty("ChargeDisplay", "true"); + automailProperties.setProperty("Markup_Percentage", "0.059"); + automailProperties.setProperty("Activity_Unit_Price", "0.224"); // Read properties FileReader inStream = null; @@ -140,10 +153,15 @@ public class Simulation { // Charge Display CHARGE_DISPLAY = Boolean.parseBoolean(automailProperties.getProperty("ChargeDisplay")); System.out.println("#Charge Display: " + CHARGE_DISPLAY); - + // Markup Percentage + MARKUP_PERCENTAGE = Double.parseDouble(automailProperties.getProperty("Markup_Percentage")); + System.out.println("Markup Percentage: " + MARKUP_PERCENTAGE); + // Activity Unit Price + ACTIVITY_UNIT_PRICE = Double.parseDouble(automailProperties.getProperty("Activity_Unit_Price")); + System.out.println("Activity_Unit_Price: " + ACTIVITY_UNIT_PRICE); return automailProperties; } - + static class ReportDelivery implements IMailDelivery { /** Confirm the delivery and calculate the total score */ diff --git a/update_log.txt b/update_log.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6e10f4f6a76cb6ac554b3f9082956a9ed7c0ea2 --- /dev/null +++ b/update_log.txt @@ -0,0 +1,35 @@ +2021/4/15 +//////////////////////////////////////////////////////// + +New variables +************************************************ +In Class Simulation: + private static double ACTIVITY_UNIT_PRICE; + private static double MARKUP_PERCENTAGE; + +In Class MailPool: + In private Class Item: + double charge; + boolean isNewItem = true; +************************************************ + +New methods +************************************************ +In Class MailPool: + public double calculateCharge; + public void setItemCharge; + public void getItemInfo;(This method is not a part of assignment, it will be removed) + public boolean isNewItem; + public int getItemDestination; + public int getPoolSize; + public void sortPriorityMailItems; +************************************************ + +New codes +************************************************ +In Class Simulation: + from line 81 to line 95 + from line 119 to line 121 + from line 156 to line 161 +************************************************ +//////////////////////////////////////////////////////// \ No newline at end of file