//package PS1; import javax.swing.*; public class Bus { public static void main(String[] args) { boolean moreToDo= true; // 1. Set parameters String title= "Boston"; double a= 2; // Avg trip duration double L1= 20; // Inner boundary double L2= 40; // Outer boundary double W= 81; // Circumference double p= 0.021; // Trip density double j= 0.25; // Access speed double b; // Change in bus time double k= 0.4; // Wait-hdwy ratio double c= 130; // Bus cost double T= 1050; // Length of day double x; // Change in Logan parking cost double s= 47; // Bus capacity double v= 0.5; // Bus speed double m= 0.8; // Peak direction double a0= 0.68; // Demand coefficients double a2= 0.0125; double a3= 0.005; double a4= 0.0001; double a5= 0.01; double yMin, yMax; // Objective weights double yIncr= 0.1; // Obj wgt increment while (moreToDo) { // 2. Read inputs String text= JOptionPane.showInputDialog("Enter change in bus time (minutes)"); b= Double.parseDouble(text); text= JOptionPane.showInputDialog("Enter change in Logan parking cost (cents)"); x= Double.parseDouble(text); text= JOptionPane.showInputDialog("Enter minimum objective weight"); yMin= Double.parseDouble(text); text= JOptionPane.showInputDialog("Enter maximum objective weight"); yMax= Double.parseDouble(text); // 3. 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; // Changes in parameters due to b, x variables from input v= (L1+5)/(L1+5-b*v); // Revised bus speed v, from b double a1 = a0 + a4*x/2 + a3*b; // Revised bus 'base market share', from b, x 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); double tolerance= 0.001; // Print output headers outside the inner loop System.out.println("Title: " + title); System.out.println("Riders Def't Hdwy Fare Rtes Mkt shr Buses y"); for (double y= yMin; y <= yMax+tolerance; y+= yIncr) { 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); //test /*System.out.println(A0); System.out.println(L0); System.out.println(B0); System.out.println(C0); System.out.println(E0); System.out.println(F0); System.out.println(G0);*/ // 4. Optimal values double h= Math.pow(3*E0*B0, 1.0/3.0); double g= Math.pow(3*F0*C0, 1.0/3.0); double n= 2.0*W/g/L2; double f= G0*(a1-a2*k*h-a5*g*A0/(4*j)); double 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); } // 5. Performance statistics double share= a1-a2*k*h-a4*f-a5*g*A0/(4*j); double riders= W*T*s*share/(L2*a4*m*L0); double revenue= f*riders/100; double cost= 4.0*W*(L1+5)*c*T/ (100*g*h*v*L2); double deficit= cost - revenue; double numBus= Math.ceil(100*cost/c/T); // 6. Output--each case n = (double)(Math.round(n*1000))/1000.0; share = (double)(Math.round(share*1000))/1000.0; y = (double)(Math.round(y*1000))/1000.0; System.out.println((int) riders + " " + (int) deficit + " " + (int) h + " " + (int) f + " " + n + " " + share + " " + (int)numBus + " " + y); } String more= JOptionPane.showInputDialog("Another run? (y/n)"); if (more.equals("n")) moreToDo= false; } System.exit(0); } }