package PS5; import javax.swing.*; public class BusSystem { // Inputs private String title= "Boston"; private double a = 2; // Avg trip duration private double L1 = 20; // Inner boundary private double L2 = 40; // Outer boundary private double W = 81; // Circumference private double p = 0.021; // Trip density private double j = 0.50; // Access speed private double b; // Change in bus time private double k = 0.4; // Wait-hdwy ratio private double c = 130; // Bus cost private double T = 1050; // Length of day private double x; // Change in Logan parking cost private double s = 47; // Bus capacity private double v = 0.5; // Bus speed private double m = 0.8; // Peak direction private double a0 = 0.48; // Demand coefficients private double a2 = 0.0125; private double a3 = 0.0005; private double a4 = 0.0001; private double a5 = 0.01; private double y; // Objective weight // Outputs private double h; // Headway private double g; // Route spacing private double n; // No of rtes private double f; // Fare private double q; // Load factor private double share; // Market share private double riders; // Ridership private double revenue; // Revenue private double cost; // Cost private double deficit; // Deficit private double numBus; // Number of buses public BusSystem(double b, double x, double y) { this.b= b; this.x= x; this.y= y; } public void setParam(double b, double x, double y) { this.b= b; this.x= x; this.y= y; } public void optimize() { // Intermediate calculations // Helper quantities double L12= L1*L1; double L13= L1*L1*L1; double L14= L1*L1*L1*L1; double L22= L2*L2; double L23= L2*L2*L2; double L24= L2*L2*L2*L2; double A0= (4*L2*(L23-L13)-3*(L24-L14))/(6*L2*(L22-L12)-4*(L23-L13)); double L0= 6*L2*s/ (p*a4*m*(3*L2*(L22-L12)-2*(L23-L13))); double denom= 3*L2*(L22-L12)-2*(L23-L13); double B0= 3*L2*L1*(4*L2*(L23-L13)-3*(L24-L14))/(denom*denom); denom= 4*L2*(L23-L13)-3*(L24-L14); double C0= L2*L1*(3*L2*(L22-L12)-2*(L23-L13))/(denom*denom); // Changes in parameters due to b, x variables from input v= (L1+5)*v/(L1+5-b*v); // Revised bus speed v, from b //v= (L1+5)/(L1+5-b*v); //incorrect Revised bus speed v, from b double a1 = a0 + a4*x/2 + a3*b; // Revised bus 'base market share', from b, x double E0= c*a4*a5*(2*y-1)/(2*j*k*k*v*p*a2*a2*a1*y); double F0= 768*c*a4*j*j*k*a2*(2*y-1)/(v*p*a1*a5*a5*y); double G0= (y-1)/((2*y-1)*a4); // Optimal values h= Math.pow(3*E0*B0, 1.0/3.0); g= Math.pow(3*F0*C0, 1.0/3.0); n= 2.0*W/g/L2; f= G0*(a1-a2*k*h-a5*g*A0/(4*j)); q= g*h*(a1-a2*k*h-a4*f-a5*g*A0/(4*j))/(a4*L0); if (q > 1.0) { h= h/Math.sqrt(q); g= g/Math.sqrt(q); n= 2.0*W/g/L2; f= (1/a4)*(a1-a2*k*h-a5*g*A0/(4*j))-L0/(g*h); q= g*h*(a1-a2*k*h-a4*f-a5*g*A0/(4*j))/(a4*L0); } // Performance statistics share= a1-a2*k*h-a4*f-a5*g*A0/(4*j); riders= W*T*s*share/(L2*a4*m*L0); revenue= f*riders/100; cost= 4.0*W*(L1+5)*c*T/ (100*g*h*v*L2); deficit= cost - revenue; numBus= Math.ceil(100*cost/c/T); } public double getHeadway() {return h;} public double getFare() {return f;} public double getRteSpacing() {return g;} public double getNoRtes() {return n;} public double getLoad() {return q;} public double getRiders() {return riders;} public double getRevenue() {return revenue;} public double getCost() {return cost;} public double getL1() {return L1;} public double getL2() {return L2;} public double getW() {return W;} }