B. Programa de Enriquecimiento
3.1. Perfil del alumnado
3.1.2. Funcionamiento cognitivo
package simulering; import java.util.*; import java.io.*;
public class Systemet {
// Declaring variables and parameters int maxTravellers=0; int maxTravellersHour; int maxNeed=0; int maxUsersPerHours=0; int longTravel=0; int fossilSS=0; int fossilST=0; int fossilO=0; int fossilW=0; int electricSS=0; int electricST=0; int electricO=0; int electricW=0; int maxElectricCar=0; int maxFossilCar=0; int ID; int number; int totalRents;
//Arrays to be containing distributions Double hoursProbWork[] = new Double [24];
Double hoursProbServiceShop[] = new Double [24]; Double hoursProbSpareTime[] = new Double [24]; Double hoursProbOther[] = new Double [24]; Double hoursProbAll[] = new Double [24]; public static int [] usersPerHour;
public static Double [] distribution = new Double [24]; int intensityHours[] = new int [24];
int queueHours[] = new int [24];
Double hoursProb[] = new Double [24];
public static int averageUsersHour []= new int [24]; ArrayList residentsArray = new ArrayList(); ArrayList<Integer> queue = new ArrayList(); ArrayList<String> typeArray = new ArrayList(); int tempHour;
int time=0; int day=1; int dayCount=1; int yearCount=0;
int years=2; int months=12; int weeksPerMonth=4; int weeks=4*12*years;
58
double percentageCarPool=1.0; int totalResidents=4500;
int residents=(int)(Math.ceil(totalResidents*percentageCarPool)); // 4500 Alt 2 //According to Östra Sala Backe
// Loading statistics and empiric data
public Systemet(String filename) throws IOException{ Properties readIn = new Properties();
FileReader fileReader = new FileReader(filename); readIn.load(fileReader);
//Initially creates an object for every resident for (int num=0; num<residents; num++){
Inhabitant humanName = new Inhabitant(ID); residentsArray.add(humanName);
}
//Allocates the right probability to travel for each hour (given in "info.txt")
for(int i=0; i<24; i++){ String s = "s"; String a = "a"; String b = "b"; String c = "c"; String d = "d"; String e = "e"; number = i+1;
String tempS = s+number; String tempA = a+number; String tempB = b+number; String tempC = c+number; String tempD = d+number; String tempE = e+number;
hoursProb[i] = Double.parseDouble(readIn.getProperty(tempS)); hoursProbWork[i] = Double.parseDouble(readIn.getProperty(tempA)); hoursProbServiceShop[i] = Double.parseDouble(readIn.getProperty(tempB)); hoursProbSpareTime[i] = Double.parseDouble(readIn.getProperty(tempC)); hoursProbOther[i] = Double.parseDouble(readIn.getProperty(tempD)); hoursProbAll[i] = Double.parseDouble(readIn.getProperty(tempE)); if (i>14 && i<19){ // Reducing probability to take out a car in work/studies errands in the afternoon early evening
double temp=(hoursProbWork[i]*0.73); double temp2=temp/13244; hoursProbAll[i]=hoursProbAll[i]-temp; hoursProb[i]=hoursProb[i]-temp2; } hoursProbWork[i]=hoursProbWork[i]/hoursProbAll[i]; hoursProbServiceShop[i]=hoursProbServiceShop[i]/hoursProbAll[i]; hoursProbSpareTime[i]=hoursProbSpareTime[i]/hoursProbAll[i]; hoursProbOther[i]=hoursProbOther[i]/hoursProbAll[i]; hoursProbAll[i]=hoursProbAll[i]/hoursProbAll[i]; }
//Calls a method that, returnerar carUsersHour som en lista (array)
59
usersPerHour = sortEm(percentageCarPool, totalResidents, maxElectricCar, maxFossilCar, fossilSS,
fossilST, fossilO, fossilW, electricSS, electricST, electricO, electricW,
longTravel, typeArray, hoursProbSpareTime, hoursProbServiceShop, hoursProbOther, maxTravellersHour, maxTravellers, maxNeed, days, day, queue, ID, time, residents, hoursProb,
intensityHours, residentsArray); for(int i=0; i<24; i++){
averageUsersHour[i] = (int)(Math.ceil(usersPerHour[i]/days)); if (maxUsersPerHours < averageUsersHour[i]){ maxUsersPerHours = averageUsersHour[i]; tempHour = i; } } }
public static int [] sortEm(double percentageCarPool, int totalResidents, int maxElectricCar, int maxFossilCar,
int fossilSS, int fossilST, int fossilO, int fossilW, int electricSS, int electricST, int electricO, int electricW, int longTravel,
ArrayList typeArray, Double hoursProbSpareTime[],
Double hoursProbServiceShop[], Double hoursProbOther[], int maxTravellersHour,
int maxTravellers, int maxNeed, int days, int day, ArrayList<Integer> queue,
int ID, int time, int residents,
Double hoursProb[], int carUsersHour[], ArrayList residentsArray){ int hours=0; int electricCar=0; int fossilCar=0; int pass=0; int temppass=0; double percentChooseEl=(6.6+7.8+20.0+9.8+9.8+21.9+10.4)/100; double percentageLongTravel=(73/5000);// In fact it's 73*10^6 and 5*10^9
double percentLongTravelByCar=0.68;
while (hours<24){ //While-loop over 24 hours int serviceShop=0; int spareTime=0; int work=0; int other=0; int travellers=0; boolean checkPassenger;
// Picks out all the travellers given during an specific hour
travellers = getTravellers(residentsArray.size(), hoursProb[hours]); maxTravellers = checkTravellers(maxTravellers, travellers); //Keeps count on the max of travellers during an hour and which hour.
// Car users are calculated according to scenario, and rounded up to an int
int carUsers=(int) (Math.ceil(0.43*travellers)); //Number of car users ceiled to nearest higher integer
60
carUsersHour[hours]+=(int)carUsers; //Adds car users to to earlier value, each hour
// All users are sorted to category of car usage as well as added between two arrays, a "busy" array and a avaliable array
if (carUsers>0){ //Allocates car users so that they wont get back into the loop
Queue sorterare = new Queue(); electricCar=0;
fossilCar=0;
for (int m=1; m<=carUsers; m++){ checkPassenger=false;
double randomTal= Math.random(); if (randomTal<percentageLongTravel){ double new2Random=Math.random(); if (new2Random < percentLongTravelByCar){ longTravel++; typeArray.add("F"); double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraLongTravel(queue, 1, checkPassenger); if (residentsArray.size()>1){ residentsArray.remove(m); } else{
residentsArray = new ArrayList(); } } } else{
if (residentsArray.size()>1){
residentsArray.remove(m); //If a user exist, remove it if (randomTal<hoursProbServiceShop[hours]){
double newRandom = Math.random();
if (0.9<newRandom){ // 10% to choose an diesel car fossilSS++;
typeArray.add("F");
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraServiceShop(queue, 1, checkPassenger); } else{ electricSS++; typeArray.add("E");
61
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraServiceShop(queue, 1, checkPassenger); } serviceShop++; }
else if(randomTal < (hoursProbSpareTime[hours] + hoursProbServiceShop[hours])){
double newRandom = Math.random();
if(0.55<newRandom){ // 55 % choose an diesel car fossilST++;
spareTime++;
typeArray.add("F");
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraSpareTime(queue, 1, checkPassenger); } else{ electricST++; spareTime++; typeArray.add("E"); double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraSpareTime(queue, 1, checkPassenger); } }
else if(randomTal < (hoursProbSpareTime[hours] +
hoursProbServiceShop[hours] + hoursProbOther[hours])){ double newRandom = Math.random();
if (0.55<newRandom){ // 55 % choose an diesel car fossilO++;
typeArray.add("F");
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true; typeArray.add("P"); residentsArray.remove(m); } sorterare.sorteraOther(queue, 1, checkPassenger); } else{ electricO++; typeArray.add("E"); double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true;
typeArray.add("P");
62 } sorterare.sorteraOther(queue, 1, checkPassenger); } other++; } else{
double newRandom = Math.random(); if (percentChooseEl<newRandom){ electricW++;
typeArray.add("E");
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true;
typeArray.add("P");
residentsArray.remove(m);
}
sorterare.sorteraWork(queue, 1, hours, checkPassenger); }
else{ fossilW++;
typeArray.add("F");
double randomPass=Math.random(); if (randomPass<0.27 && carUsers>1){ checkPassenger=true;
typeArray.add("P");
residentsArray.remove(m);
}
sorterare.sorteraWork(queue, 1, hours, checkPassenger); }
work++;
} } else{
residentsArray = new ArrayList(); checkPassenger=false;
if (randomTal<hoursProbServiceShop[hours]){ double newRandom = Math.random();
if (0.9<newRandom){ fossilSS++; typeArray.add("F"); sorterare.sorteraServiceShop(queue, 1, checkPassenger); } else{ electricSS++; typeArray.add("E"); sorterare.sorteraServiceShop(queue, 1, checkPassenger); } serviceShop++; }
else if(randomTal < (hoursProbSpareTime[hours] + hoursProbServiceShop[hours])){
double newRandom = Math.random(); if(0.55<newRandom){ fossilST++; spareTime++; typeArray.add("F"); sorterare.sorteraSpareTime(queue, 1, checkPassenger); }
63 else{ electricST++; spareTime++; typeArray.add("E"); sorterare.sorteraSpareTime(queue, 1, checkPassenger); } }
else if(randomTal < (hoursProbSpareTime[hours] + hoursProbServiceShop[hours] + hoursProbOther[hours])){ double newRandom = Math.random(); if (0.55<newRandom){ fossilO++; typeArray.add("F"); sorterare.sorteraOther(queue, 1, checkPassenger); } else{ electricO++; typeArray.add("E"); sorterare.sorteraOther(queue, 1, checkPassenger); } other++; } else{ double newRandom = Math.random(); if (percentChooseEl<newRandom){ electricW++; typeArray.add("E"); sorterare.sorteraWork(queue, 1, hours, checkPassenger); }
else{ fossilW++; typeArray.add("F"); sorterare.sorteraWork(queue, 1, hours, checkPassenger); } work++; } } } }
// Add the user sorterare who will be sorted in class Queue for (int n=0; n<queue.size(); n++){ //If a inhabintat is finished with a car, return the inhabitant if(queue.get(n)<1){ //If done with car, remove from sorterad queue.remove(n); //If done with car typeArray.remove(n); Inhabitant humanName = new Inhabitant(ID); //Add that user to residentsArray residentsArray.add(humanName); }
else if(queue.get(n) < 0) { //Should never happen queue.remove(n); typeArray.remove(n); }
else{ int tempNum = queue.get(n)-1; //Lowers queue time by 1 hour queue.set(n, tempNum); }
}
64
else{
fossilCar=0; electricCar=0; }
fossilCar= checkFossil(typeArray, fossilCar);
electricCar= checkElectric(typeArray, electricCar);
maxNeed=checkNeed((fossilCar+electricCar), maxNeed); // Checking maximum need and different types of cars
maxElectricCar = checkMax(maxElectricCar, electricCar); maxFossilCar = checkMax(maxFossilCar, fossilCar);
hours++; } // End of hourwhile-loop if (hours==24){ hours=0; day+=1; }
// Calculating distances for travels by type of travel if ((day+1)>days){
countStuff(electricSS,electricST,electricO,electricW,fossilSS,fossilST ,fossilO,fossilW, longTravel, carUsersHour);
} if (day<days)
return sortEm(percentageCarPool, totalResidents, maxElectricCar, maxFossilCar, fossilSS,
fossilST, fossilO, fossilW, electricSS, electricST, electricO, electricW, longTravel, typeArray, hoursProbSpareTime,
hoursProbServiceShop,
hoursProbOther, maxTravellersHour, maxTravellers, maxNeed, days, day, queue, ID, time, residents, hoursProb,
carUsersHour, residentsArray); else
System.out.println();
System.out.println("The maximum number of electric cars during one hour is "+maxElectricCar+" and the maxnumber for fossil cars is "+maxFossilCar);
System.out.println("The total maximum cars (both electric and fossil) needed during one hour is "+maxNeed);
int residences; //According to Östra Sala Backe if(totalResidents>5000){ residences=2500;} else{residences=2000;} double maximumNeed=maxNeed*1.0; double doubleResidences=residences*percentageCarPool; double pph=maximumNeed/doubleResidences; ;
System.out.println("The lowest parking standard possible is "+pph); System.out.println();
return carUsersHour; }
65
private static void countStuff(int electricSS,int electricST,int electricO, int electricW,
int fossilSS, int fossilST, int fossilO,int fossilW, int longTravel, int carUsersHour[]){
// Average distances for each travel typ int longTravelMedian=155;
double SSDistance= 30.5; double WDistance=22.5; double STDistance=51.0; double ODistance=51.5;
//Emissions from each fuel type [kg Co2/km] and fuel prices double ethanol=0.080;
double diesel=0.124; double electricEm=0.020;
double costFossilKM1=(14.49*0.5)/(10); // Fuelprice diesel 14.49 SEK/liter
double costFossilKM2=(9.49*0.9)/(10); // Fuelprice ethanol 9.49 SEK/liter
double costElectricKM=(2.743)/(10); // Electric price 2.743 SEK/kWh // Calculating distances double distanceFossil=0.5*((fossilSS*SSDistance)+(fossilST*STDistance)+(fossi lO*ODistance)+(fossilW*WDistance)); double distanceElectric=(electricSS*SSDistance)+(electricST*STDistance)+(elec tricO*ODistance)+(electricW*WDistance); double percantageDistance=Math.ceil(((2*distanceFossil)/((2*distanceFossil)+d istanceElectric))*100); // Calculating costs double costFossil1=distanceFossil*costFossilKM1; double costFossil2=distanceFossil*costFossilKM2; double costElectric=distanceElectric*costElectricKM; double costLong = ((0.5*longTravel*longTravelMedian)*costFossilKM1)+((0.5*longTravel*lon gTravelMedian)*costFossilKM2); double totalFossil=costFossil1+costFossil2+costLong; double totalCostTravels=costFossil1+costFossil2+costElectric+costLong; double percentageCosts=Math.ceil((totalFossil/totalCostTravels)*100); //Calculating emissions double ethanolEmissions=distanceFossil*ethanol; double dieselEmissions=distanceFossil*diesel; double electricEmissions=distanceElectric*electricEm; double totalEmissions=ethanolEmissions+dieselEmissions+electricEmissions; double percentageEmissions=Math.ceil(((ethanolEmissions+dieselEmissions)/tota lEmissions)*100);
System.out.println("COSTS AND EMISSIONS"); System.out.println("Distance traveled:
"+(distanceElectric+(distanceFossil*2))+" km");
System.out.println("Fossil cars answers to "+percantageDistance+"% of distance travelled");
66
System.out.println("The fossil cost answers to circa "+percentageCosts+"% of the costs");
System.out.println("Total fuel costs for travels is: "+totalCostTravels+ " SEK");
System.out.println();
System.out.println("Total emissions are:
"+(electricEmissions+dieselEmissions+ethanolEmissions)+ " kg CO2"); System.out.println("The fossil cars answers to circa
"+percentageEmissions+"% of the emissions"); System.out.println();
}
public static int checkFossil(ArrayList<String> typeArray, int car){ for (int n=0; n<typeArray.size(); n++){
if(typeArray.get(n)=="F"){ car++; } } return car; }
public static int checkElectric(ArrayList<String> typeArray, int car){ for (int n=0; n<typeArray.size(); n++){
if(typeArray.get(n)=="E"){ car++; } } return car; }
public static int checkNeed(int size, int maxNeed){ if (maxNeed==0){ maxNeed=size;} if (maxNeed<size){ maxNeed=size; } return maxNeed; }
public static int checkMax(int maxCar, int car){ if (maxCar<car){
maxCar=car; } return maxCar; }
public static int getTravellers(int size, double hoursProb){ int travellers = 0;
for(int i=0; i<size; i++){ if(Math.random()<hoursProb){ travellers+=1; } } return travellers; }
public static int checkTravellers(int maxTravellers, int travellers){ if (maxTravellers<travellers){
maxTravellers=travellers; }
return maxTravellers; }
67
}