Skip to content
Snippets Groups Projects
Commit 6dd4cc2e authored by Zening Li's avatar Zening Li
Browse files

Update 0.1

parent 751195f5
Branches final-version
No related tags found
No related merge requests found
Pipeline #74264 failed
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -19,6 +19,8 @@ public class MailItem { ...@@ -19,6 +19,8 @@ public class MailItem {
/** The weight in grams of the mail item */ /** The weight in grams of the mail item */
protected final int weight; protected final int weight;
private double serviceFee;
/** /**
* Constructor for a MailItem * Constructor for a MailItem
* @param dest_floor the destination floor intended for this mail item * @param dest_floor the destination floor intended for this mail item
...@@ -32,6 +34,10 @@ public class MailItem { ...@@ -32,6 +34,10 @@ public class MailItem {
this.weight = weight; this.weight = weight;
} }
public void setServiceFee(double serviceFee){
this.serviceFee = serviceFee;
}
@Override @Override
public String toString(){ public String toString(){
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d", id, arrival_time, destination_floor, weight); return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d", id, arrival_time, destination_floor, weight);
......
package automail; package automail;
import java.util.LinkedList; import exceptions.ItemTooHeavyException;
import simulation.Building;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedList;
import java.util.ListIterator; 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 * 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. * if a robot returns with some undelivered items - these are added back to the MailPool.
...@@ -13,9 +14,10 @@ import exceptions.ItemTooHeavyException; ...@@ -13,9 +14,10 @@ import exceptions.ItemTooHeavyException;
* *
*/ */
public class MailPool { public class MailPool {
private class Item { private class Item {
int destination; int destination;
double charge;
boolean isNewItem = true;
MailItem mailItem; MailItem mailItem;
// Use stable sort to keep arrival time relative positions // Use stable sort to keep arrival time relative positions
...@@ -57,7 +59,53 @@ public class MailPool { ...@@ -57,7 +59,53 @@ public class MailPool {
pool.sort(new ItemComparator()); 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. * load up any waiting robots with mailItems, if any.
......
...@@ -22,7 +22,6 @@ public class Robot { ...@@ -22,7 +22,6 @@ public class Robot {
private int destination_floor; private int destination_floor;
private MailPool mailPool; private MailPool mailPool;
private boolean receivedDispatch; private boolean receivedDispatch;
private MailItem deliveryItem = null; private MailItem deliveryItem = null;
private MailItem tube = null; private MailItem tube = null;
...@@ -173,4 +172,5 @@ public class Robot { ...@@ -173,4 +172,5 @@ public class Robot {
if (tube.weight > INDIVIDUAL_MAX_WEIGHT) throw new ItemTooHeavyException(); if (tube.weight > INDIVIDUAL_MAX_WEIGHT) throw new ItemTooHeavyException();
} }
} }
package simulation; package simulation;
import java.util.*;
import automail.MailItem; import automail.MailItem;
import automail.MailPool; import automail.MailPool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/** /**
* This class generates the mail * This class generates the mail
*/ */
...@@ -118,6 +121,10 @@ public class MailGenerator { ...@@ -118,6 +121,10 @@ public class MailGenerator {
} }
public void setServiceFee(){
}
/** /**
* Given the clock time, put the generated mails into the mailPool. * Given the clock time, put the generated mails into the mailPool.
* So that the robot will can pick up the mails from the pool. * So that the robot will can pick up the mails from the pool.
......
package simulation; package simulation;
import automail.Automail;
import automail.MailItem;
import automail.MailPool;
import com.unimelb.swen30006.wifimodem.WifiModem;
import exceptions.ExcessiveDeliveryException; import exceptions.ExcessiveDeliveryException;
import exceptions.ItemTooHeavyException; import exceptions.ItemTooHeavyException;
import exceptions.MailAlreadyDeliveredException; import exceptions.MailAlreadyDeliveredException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Properties;
import com.unimelb.swen30006.wifimodem.WifiModem;
import automail.Automail;
import automail.MailItem;
import automail.MailPool;
/** /**
* This class simulates the behaviour of AutoMail * This class simulates the behaviour of AutoMail
...@@ -23,6 +19,8 @@ public class Simulation { ...@@ -23,6 +19,8 @@ public class Simulation {
private static int NUM_ROBOTS; private static int NUM_ROBOTS;
private static double CHARGE_THRESHOLD; private static double CHARGE_THRESHOLD;
private static boolean CHARGE_DISPLAY; private static boolean CHARGE_DISPLAY;
private static double ACTIVITY_UNIT_PRICE;
private static double MARKUP_PERCENTAGE;
/** Constant for the mail generator */ /** Constant for the mail generator */
private static int MAIL_TO_CREATE; private static int MAIL_TO_CREATE;
...@@ -68,7 +66,6 @@ public class Simulation { ...@@ -68,7 +66,6 @@ public class Simulation {
} catch (Exception mException) { } catch (Exception mException) {
mException.printStackTrace(); mException.printStackTrace();
} }
/** /**
* This code section is for running a simulation * This code section is for running a simulation
*/ */
...@@ -76,12 +73,26 @@ public class Simulation { ...@@ -76,12 +73,26 @@ public class Simulation {
MailPool mailPool = new MailPool(NUM_ROBOTS); MailPool mailPool = new MailPool(NUM_ROBOTS);
Automail automail = new Automail(mailPool, new ReportDelivery(), NUM_ROBOTS); Automail automail = new Automail(mailPool, new ReportDelivery(), NUM_ROBOTS);
MailGenerator mailGenerator = new MailGenerator(MAIL_TO_CREATE, MAIL_MAX_WEIGHT, mailPool, seedMap); MailGenerator mailGenerator = new MailGenerator(MAIL_TO_CREATE, MAIL_MAX_WEIGHT, mailPool, seedMap);
/** Generate all the mails */ /** Generate all the mails */
mailGenerator.generateAllMail(); mailGenerator.generateAllMail();
while(MAIL_DELIVERED.size() != mailGenerator.MAIL_TO_CREATE) { while(MAIL_DELIVERED.size() != mailGenerator.MAIL_TO_CREATE) {
// System.out.printf("Delivered: %4d; Created: %4d%n", MAIL_DELIVERED.size(), mailGenerator.MAIL_TO_CREATE); // System.out.printf("Delivered: %4d; Created: %4d%n", MAIL_DELIVERED.size(), mailGenerator.MAIL_TO_CREATE);
mailGenerator.addToMailPool(); 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 { try {
automail.mailPool.loadItemsToRobot(); automail.mailPool.loadItemsToRobot();
for (int i=0; i < NUM_ROBOTS; i++) { for (int i=0; i < NUM_ROBOTS; i++) {
...@@ -105,7 +116,9 @@ public class Simulation { ...@@ -105,7 +116,9 @@ public class Simulation {
automailProperties.setProperty("Floors", "10"); automailProperties.setProperty("Floors", "10");
automailProperties.setProperty("Mail_to_Create", "80"); automailProperties.setProperty("Mail_to_Create", "80");
automailProperties.setProperty("ChargeThreshold", "0"); 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 // Read properties
FileReader inStream = null; FileReader inStream = null;
...@@ -140,7 +153,12 @@ public class Simulation { ...@@ -140,7 +153,12 @@ public class Simulation {
// Charge Display // Charge Display
CHARGE_DISPLAY = Boolean.parseBoolean(automailProperties.getProperty("ChargeDisplay")); CHARGE_DISPLAY = Boolean.parseBoolean(automailProperties.getProperty("ChargeDisplay"));
System.out.println("#Charge Display: " + CHARGE_DISPLAY); 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; return automailProperties;
} }
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment