Newer
Older
/**
* Observer
* Author: Thibaut
* Description:
*/
model Observer
import "./FinalDestinationManager.gaml"
import "./LogisticProvider.gaml"
import "./Batch.gaml"
import "./Warehouse.gaml"
Thibaut Démare
committed
import "./Parameters.gaml"
Thibaut Démare
committed
bool saveObservations <- false;
Thibaut Démare
committed
list<float> averagesLPEfficiency <- [];
float averageLPEfficiency <- 0.0;
int numberofEmptyStockInFinalDests <- 0;
int numberOfEmptyStockInWarehouses <- 0;
Thibaut Démare
committed
float stockInFinalDest <- 0.0;
float freeSurfaceInFinalDest <- 0.0;
Thibaut Démare
committed
float stockInWarehouse <- 0.0;
float freeSurfaceInWarehouse <- 0.0;
Thibaut Démare
committed
int cumulativeNumberOfBatchProviderToLarge <- 0;
int cumulativeNumberOfBatchLargeToClose <- 0;
int cumulativeNumberOfBatchCloseToFinal <- 0;
Thibaut Démare
committed
float cumulativeStockOnRoads <- 0.0;
float stockOnRoadsProviderToLarge <- 0.0;
float cumulativeStockOnRoadsProviderToLarge <- 0.0;
float cumulativeStockOnRoadsLargeToClose <- 0.0;
float cumulativeStockOnRoadsCloseToFinal <- 0.0;
Thibaut Démare
committed
// These variables are used to measure the efficiency of the logistic provider to deliver quickly the goods
Thibaut Démare
committed
float averageTimeToBeDelivered <- 0.0;
reflex updateStockInBuildings {
do computeStockInFinalDests;
do computeStockInWarehouses;
}
Thibaut Démare
committed
/*
* This method computes the free surface of every final destination, the surface used, and the number of stock shortages
* This number of stock shortages is stored in an array 'lpEfficiencies' in order to used it as a perforamnce measure of the logistic provider collaborating with the final destination manager.
*/
Thibaut Démare
committed
stockInFinalDest <- 0.0;
freeSurfaceInFinalDest <- 0.0;
numberofEmptyStockInFinalDests <- 0;
float totalNumberOfStock <- 0.0;
Thibaut Démare
committed
ask FinalDestinationManager {
Thibaut Démare
committed
float nbStockShortages <- 0.0;
Thibaut Démare
committed
ask self.building.stocks {
stockInFinalDest <- stockInFinalDest + self.quantity;
Thibaut Démare
committed
if(self.quantity = 0){
nbStockShortages <- nbStockShortages + 1.0;
}
tempStock <- tempStock + self.quantity;
totalNumberOfStock <- totalNumberOfStock + 1;
if(self.quantity = 0){
numberofEmptyStockInFinalDests <- numberofEmptyStockInFinalDests + 1;
}
Thibaut Démare
committed
}
Thibaut Démare
committed
self.localLPEfficiencies <- localLPEfficiencies + nbStockShortages;
freeSurfaceInFinalDest <- freeSurfaceInFinalDest + (surface - tempStock);
Thibaut Démare
committed
}
Thibaut Démare
committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* This reflex updates every step the average efficiency of every logistic provider, but also the estimated efficiency at the FDM level.
*/
reflex updateAverageLPEfficiency {
float currentLPEfficiency <- 0;
ask FinalDestinationManager {
int i <- 0;
self.localAverageLPEfficiency <- 0;
loop while: i < length(localLPEfficiencies) {
self.localAverageLPEfficiency <- self.localAverageLPEfficiency + localLPEfficiencies[i];
i <- i + 1;
}
self.localAverageLPEfficiency <- self.localAverageLPEfficiency / length(localLPEfficiencies);
currentLPEfficiency <- currentLPEfficiency + self.localAverageLPEfficiency;
}
currentLPEfficiency <- currentLPEfficiency / length(FinalDestinationManager);
averagesLPEfficiency <- averagesLPEfficiency + 0.0;
if(length(averagesLPEfficiency) > numberOfStepConsideredForLPEfficiency){
remove index: 0 from: averagesLPEfficiency;
}
averagesLPEfficiency[length(averagesLPEfficiency)-1] <- averagesLPEfficiency[length(averagesLPEfficiency)-1] + currentLPEfficiency;
int i <- 0;
averageLPEfficiency <- 0.0;
loop while: i < length(averagesLPEfficiency) {
averageLPEfficiency <- averageLPEfficiency + averagesLPEfficiency[i];
i <- i + 1;
}
averageLPEfficiency <- averageLPEfficiency / length(averagesLPEfficiency);
}
Thibaut Démare
committed
stockInWarehouse <- 0.0;
freeSurfaceInWarehouse <- 0.0;
numberOfEmptyStockInWarehouses <- 0;
float totalNumberOfStock <- 0.0;
Thibaut Démare
committed
ask Warehouse {
Thibaut Démare
committed
ask self.stocks {
stockInWarehouse <- stockInWarehouse + self.quantity;
tempStock <- tempStock + self.quantity;
totalNumberOfStock <- totalNumberOfStock + 1;
if(self.quantity = 0){
numberOfEmptyStockInWarehouses <- numberOfEmptyStockInWarehouses + 1;
}
Thibaut Démare
committed
}
freeSurfaceInWarehouse <- freeSurfaceInWarehouse + (surfaceUsedForLH - tempStock);
Thibaut Démare
committed
}
}
Thibaut Démare
committed
// Init to zero
totalNumberOfBatch <- 0;
numberOfBatchProviderToLarge <- 0;
numberOfBatchLargeToClose <- 0;
numberOfBatchCloseToFinal <- 0;
Thibaut Démare
committed
stockOnRoadsProviderToLarge <- 0.0;
stockOnRoadsLargeToClose <- 0.0;
stockOnRoadsCloseToFinal <- 0.0;
Thibaut Démare
committed
// Filter the right agents
if(!marked){
marked <- true;
if(self.position = 1){
cumulativeNumberOfBatchProviderToLarge <- cumulativeNumberOfBatchProviderToLarge + 1;
cumulativeStockOnRoadsProviderToLarge <- cumulativeStockOnRoadsProviderToLarge + self.overallQuantity;
}
else if(self.position = 2){
cumulativeNumberOfBatchLargeToClose <- cumulativeNumberOfBatchLargeToClose + 1;
cumulativeStockOnRoadsLargeToClose <- cumulativeStockOnRoadsLargeToClose + self.overallQuantity;
}
else if(self.position = 3){
cumulativeNumberOfBatchCloseToFinal <- cumulativeNumberOfBatchCloseToFinal + 1;
cumulativeStockOnRoadsCloseToFinal <- cumulativeStockOnRoadsCloseToFinal + self.overallQuantity;
}
if(self.position > 0){
cumulativeNumberOfBatch <- cumulativeNumberOfBatch + 1;
Thibaut Démare
committed
cumulativeStockOnRoads <- cumulativeStockOnRoads + self.overallQuantity;
}
}
if(self.position = 1){
Thibaut Démare
committed
numberOfBatchProviderToLarge <- numberOfBatchProviderToLarge + 1;
stockOnRoadsProviderToLarge <- stockOnRoadsProviderToLarge + self.overallQuantity;
else if(self.position = 2){
numberOfBatchLargeToClose <- numberOfBatchLargeToClose + 1;
stockOnRoadsLargeToClose <- stockOnRoadsLargeToClose + self.overallQuantity;
else if(self.position = 3){
numberOfBatchCloseToFinal <- numberOfBatchCloseToFinal + 1;
stockOnRoadsCloseToFinal <- stockOnRoadsCloseToFinal + self.overallQuantity;
if(self.position > 0){
totalNumberOfBatch <- totalNumberOfBatch + 1;
}
stockOnRoads <- stockOnRoadsProviderToLarge + stockOnRoadsLargeToClose + stockOnRoadsCloseToFinal;
reflex update_average_time_to_deliver {
Thibaut Démare
committed
// Update the average time to deliver (at the LPs level)
int i <- 0;
int sum <- 0;
ask LogisticProvider {
int j <- 0;
Thibaut Démare
committed
loop while: 50 < length(timeToDeliver) {
remove index: 0 from: timeToDeliver;
}
loop while: j<length(timeToDeliver) {
sum <- sum + timeToDeliver[j];
j <- j + 1;
i <- i + 1;
}
}
if(i > 0){
averageTimeToDeliver <- (sum/i);
Thibaut Démare
committed
// Update the average time to be delivered (at the FDMs level)
i <- 0;
sum <- 0;
ask FinalDestinationManager {
int j <- 0;
int localSum <- 0;
Thibaut Démare
committed
loop while: 50 < length(timeToBeDelivered) {
remove index: 0 from: timeToBeDelivered;
}
Thibaut Démare
committed
loop while: j<length(timeToBeDelivered) {
sum <- sum + timeToBeDelivered[j];
localSum <- localSum + timeToBeDelivered[j];
Thibaut Démare
committed
j <- j + 1;
i <- i + 1;
}
if( length(timeToBeDelivered) > 0){
localTimeToBeDelivered <- localSum / length(timeToBeDelivered);
}
Thibaut Démare
committed
}
if(i > 0){
averageTimeToBeDelivered <- (sum/i);
}
Thibaut Démare
committed
reflex saveObservations when: saveObservations {
save "" + ((time/3600.0) as int) + ";" +stockInWarehouse + ";" + freeSurfaceInWarehouse + ";"
to: "stocks_warehouses" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" +stockInFinalDest + ";" + freeSurfaceInFinalDest + ";"
to: "stocks_final_dests" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + cumulativeNumberOfBatch + ";" + cumulativeNumberOfBatchProviderToLarge + ";" + cumulativeNumberOfBatchLargeToClose + ";" + cumulativeNumberOfBatchCloseToFinal + ";"
to: "cumulative_number_batches" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + cumulativeStockOnRoads + ";" + cumulativeStockOnRoadsProviderToLarge + ";" + cumulativeStockOnRoadsLargeToClose + ";" + cumulativeStockOnRoadsCloseToFinal + ";"
to: "cumulative_stock_on_roads" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + totalNumberOfBatch + ";" + numberOfBatchProviderToLarge + ";" + numberOfBatchLargeToClose + ";" + numberOfBatchCloseToFinal + ";"
to: "number_batches" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + stockOnRoads + ";" + stockOnRoadsProviderToLarge + ";" + stockOnRoadsLargeToClose + ";" + stockOnRoadsCloseToFinal + ";"
to: "stock_on_roads" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + numberofEmptyStockInFinalDests + ";"
to: "number_empty_stock_final_dest" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + numberOfEmptyStockInWarehouses + ";"
to: "number_empty_stock_warehouses" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + averageTimeToDeliver + ";"
to: "average_time_to_deliver" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
save "" + ((time/3600.0) as int) + ";" + averageTimeToBeDelivered + ";"
to: "average_time_to_be_delivered" + "_AS" + adoptedStrategy + ".csv" type: text rewrite: false;
Thibaut Démare
committed
}