Skip to content
Snippets Groups Projects
Commit a5b85d5e authored by Isobel's avatar Isobel
Browse files

made changes related to activity tracking

parent 0f62ec67
No related branches found
No related tags found
No related merge requests found
This project has a lot of really weird config that it took me a while to figure out, so the best way I can think to share files is to only share src/ from the Automail subfolder
I'll explain when we meet!
\ No newline at end of file
......@@ -8,7 +8,6 @@ public class Automail {
public MailPool mailPool;
public Automail(MailPool mailPool, IMailDelivery delivery, int numRobots) {
System.out.println("Test Line");
/** Initialize the MailPool */
this.mailPool = mailPool;
......
......@@ -19,6 +19,18 @@ public class MailItem {
/** The weight in grams of the mail item */
protected final int weight;
/*Mail item now tracks several variables associated with charge*/
/** The number of activity units associated with delivering this mail item*/
private double activity_units;
/** The service fee looked up at time of delivery*/
private double service_fee;
/** The portion of cost associated with activity units*/
private double activity_cost;
/** The total charge for delivering the item*/
private double charge;
/**
* Constructor for a MailItem
* @param dest_floor the destination floor intended for this mail item
......@@ -30,6 +42,12 @@ public class MailItem {
this.id = String.valueOf(hashCode());
this.arrival_time = arrival_time;
this.weight = weight;
/*Initialise activity units and costs to zero*/
this.activity_units = 0;
this.service_fee = 0;
this.activity_cost = 0;
this.charge = 0;
}
@Override
......@@ -69,6 +87,35 @@ public class MailItem {
return weight;
}
/**
* Increases the activity unit counter
* @param num_units the number of units to add
*/
public void addActivityUnits(double num_units) {
this.activity_units += num_units;
}
/**
*
* @return the number of activity units incurred
*/
public double getActivityUnits() {
return activity_units;
}
public double getCost() {
return service_fee + activity_cost;
}
/**
* Modified version of the toString() method that includes information related to the charge
*/
public String toStringWithCharge(){
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d | Charge: %.2f | Cost: %.2f | Fee: %.2f | Activity: %.2f",
id, arrival_time, destination_floor, weight, charge, getCost(), service_fee, activity_cost);
}
static private int count = 0;
static private Map<Integer, Integer> hashMap = new TreeMap<Integer, Integer>();
......@@ -79,4 +126,5 @@ public class MailItem {
if (hash == null) { hash = count++; hashMap.put(hash0, hash); }
return hash;
}
}
......@@ -41,7 +41,7 @@ public class MailPool {
private LinkedList<Item> pool;
private LinkedList<Robot> robots;
public MailPool(int nrobots){
public MailPool(int nrobots){ //does it need a number of robots??????
// Start empty
pool = new LinkedList<Item>();
robots = new LinkedList<Robot>();
......
......@@ -13,6 +13,10 @@ public class Robot {
static public final int INDIVIDUAL_MAX_WEIGHT = 2000;
/*Number of activity units associated with each activity*/
static private final double MOVEMENT_ACTIVITY_UNITS = 5;
static private final double LOOKUP_ACTIVITY_UNITS = 0.1;
IMailDelivery delivery;
protected final String id;
/** Possible states the robot can be in */
......@@ -88,6 +92,10 @@ public class Robot {
break;
case DELIVERING:
if(current_floor == destination_floor){ // If already here drop off either way
/*add activity units for the delivery*/
deliveryItem.addActivityUnits(LOOKUP_ACTIVITY_UNITS);
/** Delivery complete, report this to the simulator! */
delivery.deliver(deliveryItem);
deliveryItem = null;
......@@ -109,6 +117,14 @@ public class Robot {
} else {
/** The robot is not at the destination yet, move towards it! */
moveTowards(destination_floor);
/*Increment activity units for items being carried*/
if (deliveryItem != null) {
deliveryItem.addActivityUnits(MOVEMENT_ACTIVITY_UNITS);
}
if (tube != null) {
tube.addActivityUnits(MOVEMENT_ACTIVITY_UNITS);
}
}
break;
}
......
......@@ -151,6 +151,14 @@ public class Simulation {
if(!MAIL_DELIVERED.contains(deliveryItem)){
MAIL_DELIVERED.add(deliveryItem);
System.out.printf("T: %3d > Delivered(%4d) [%s]%n", Clock.Time(), MAIL_DELIVERED.size(), deliveryItem.toString());
/*FOR TESTING: print the number of activity units incurred*/
//System.out.println("The item incurred " + deliveryItem.getActivityUnits() + " activity units");
/*FOR TESTING: print out the "with charge" version of deliveryItem's toString*/
//System.out.printf("T: %3d > Delivered(%4d) [%s]%n", Clock.Time(), MAIL_DELIVERED.size(), deliveryItem.toStringWithCharge());
// Calculate delivery score
total_delay += calculateDeliveryDelay(deliveryItem);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment