Package trams.data

Examples of trams.data.Scenario


    private void createAndStoreScenarios ( List<Route> routes, List<Vehicle> vehicles, List<Driver> drivers, int passengerSatisfaction, String playerName, double balance ) {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
       
        ApplicationContext theContext = new ClassPathXmlApplicationContext("trams/data/context.xml");
        Scenario theScenario = (Scenario) theContext.getBean("LanduffScenario");
        theScenario.setPlayerName(playerName);
        theScenario.setBalance(balance);
        theScenario.setPassengerSatisfaction(passengerSatisfaction);
        theScenario.setRoutes(routes);
        theScenario.setVehicles(vehicles);
        theScenario.setDrivers(drivers);
       
        session.save(theScenario);
        session.getTransaction().commit();
    }
View Full Code Here


     * @param scenarioName a <code>String</code> with the scenario's name.
     * @param playerName a <code>String</code> with the player's name.
     * @return a <code>boolean</code> which is true iff the simulation was created successfully.
     */
    public boolean createSimulator ( String scenarioName, String playerName ) {
        Scenario scen = createScenarioObject(scenarioName, playerName, 800000.00, START_SATISFACTION);
        theSimulator = new Simulator(scen);
        //Now for the scenario - create supplied vehicles.
        logger.debug("Creating " + scen.getNumberSuppliedVehicles() + " vehicles!");
        for ( int i = 0; i < scen.getNumberSuppliedVehicles(); i++ ) {
          Calendar deliveryDate = theSimulator.getCurrentSimTime();
          deliveryDate.add(Calendar.DAY_OF_MONTH, -1);
            scen.addVehicle(createVehicleObject(generateRandomReg(theSimulator.getShortYear()), "MyBus Single Decker", deliveryDate ));
        }
        //Also create supplied drivers.
        logger.debug("Creating " + scen.getNumberSuppliedDrivers() + " drivers!");
        for ( int i = 0; i < scen.getNumberSuppliedDrivers(); i++ ) {
          Calendar startDate = theSimulator.getCurrentSimTime();
          startDate.add(Calendar.DAY_OF_MONTH, -1);
          addDriver(generateRandomName(), 40, 5, startDate);
        }
        return true;
View Full Code Here

            String scenarioName = scenario.getAttribute("name");
            String playerName = scenario.getAttribute("pName");
            double balance = Double.parseDouble(scenario.getAttribute("balance"));
            int psgSatisfaction = Integer.parseInt(scenario.getAttribute("satisfaction"));
            //Now create the scenario object.
            Scenario myScenario = createScenarioObject(scenarioName, playerName, balance, psgSatisfaction);
            //Seventhly, create the simulation object.
            theSimulator = new Simulator(myScenario, document.getDocumentElement().getAttribute("time"), Integer.parseInt(document.getDocumentElement().getAttribute("increment")));
            //Set the difficulty level.
            theSimulator.setDifficultyLevel(document.getDocumentElement().getAttribute("difficulty"));
            //Now add the messages!!!!
            NodeList messageNode = (NodeList) xpath.evaluate("//scenario/message", document.getDocumentElement(), XPathConstants.NODESET);
            for ( int i = 0; i < messageNode.getLength(); i++ ) {
                Element messageElement = (Element) messageNode.item(i);
                //Create message element.
                theSimulator.addMessage(createMessageObject(messageElement.getAttribute("subject"), messageElement.getAttribute("text"), messageElement.getAttribute("sender"), messageElement.getAttribute("folder"), messageElement.getAttribute("date"), messageElement.getAttribute("type")));
            }
            //Fourthly, get the route details and create the route object.
            //theRoutes = new LinkedList<Route>();
            NodeList routeNode = (NodeList) xpath.evaluate("//scenario/route", document.getDocumentElement(), XPathConstants.NODESET);
            for ( int i = 0; i < routeNode.getLength(); i++ ) {
                Element routeElement = (Element) routeNode.item(i);
                //Create the route by creating the route number and valid from and valid to dates.
                String routeNumber = routeElement.getAttribute("number");
                //Create route object.
                Route route = new Route();
                route.setRouteNumber(routeNumber);
                //Now get the outward stops.
                NodeList outwardStopNodes = routeElement.getElementsByTagName("outstop");
                for ( int j = 0; j < outwardStopNodes.getLength(); j++ ) {
                    //Add each stop to the route object.
                    Element stopElement = (Element) outwardStopNodes.item(j);
                    route.addStop(stopElement.getAttribute("name"), Route.OUTWARDSTOPS);
                }
                //Now get the inward stops.
                NodeList inwardStopNodes = routeElement.getElementsByTagName("instop");
                for ( int j = 0; j < inwardStopNodes.getLength(); j++ ) {
                    //Add each stop to the route object.
                    Element stopElement = (Element) inwardStopNodes.item(j);
                    route.addStop(stopElement.getAttribute("name"), Route.RETURNSTOPS);
                }
                //Now go through and get the timetable elements.
                NodeList timetableNodes = routeElement.getElementsByTagName("timetable");
                for ( int j = 0; j < timetableNodes.getLength(); j++ ) {
                    Element timetableElement = (Element) timetableNodes.item(j);
                    //Get timetable information.
                    String[] validFromDates = timetableElement.getAttribute("validFrom").split("-");
                    Calendar validFrom = new GregorianCalendar(Integer.parseInt(validFromDates[0]), Integer.parseInt(validFromDates[1])-1, Integer.parseInt(validFromDates[2]));
                    String[] validToDates = timetableElement.getAttribute("validTo").split("-");
                    Calendar validTo = new GregorianCalendar(Integer.parseInt(validToDates[0]), Integer.parseInt(validToDates[1])-1, Integer.parseInt(validToDates[2]));
                    //Create timetable object.
                    Timetable myTimetable = new Timetable(timetableElement.getAttribute("name"), validFrom, validTo);
                    //Now add all service patterns.
                    NodeList serviceNodes = timetableElement.getElementsByTagName("servicePattern");
                    for ( int k = 0; k < serviceNodes.getLength(); k++ ) {
                        Element serviceElement = (Element) serviceNodes.item(k);
                        //Get service information.
                        String daysOfOperation = serviceElement.getAttribute("days");
                        String[] timeFrom = serviceElement.getAttribute("startTime").split(":");
                        Calendar startTime = new GregorianCalendar(2009,Calendar.AUGUST,5,Integer.parseInt(timeFrom[0]),Integer.parseInt(timeFrom[1]));
                        String[] timeTo = serviceElement.getAttribute("endTime").split(":");
                        Calendar endTime = new GregorianCalendar(2009,Calendar.AUGUST,5,Integer.parseInt(timeTo[0]),Integer.parseInt(timeTo[1]));
                        //Create service object.
                        ServicePattern myService = new ServicePattern(serviceElement.getAttribute("name"), daysOfOperation, serviceElement.getAttribute("returnTerminus"), serviceElement.getAttribute("outgoingTerminus"), startTime, endTime, Integer.parseInt(serviceElement.getAttribute("frequency")), Integer.parseInt(serviceElement.getAttribute("duration")));
                        //Add to timetable.
                        myTimetable.addServicePattern(serviceElement.getAttribute("name"), myService);
                    }
                    //Finally add this timetable to the route.
                    logger.debug("Adding " + myTimetable.getName() + " to " + route.getRouteNumber());
                    route.addTimetable(timetableElement.getAttribute("name"), myTimetable);
                }
                //Generate timetables.
                List<Service> outgoingServices = route.generateServiceTimetables(getSimulator().getCurrentSimTime(), myScenario, Route.OUTWARDSTOPS);
                List<Service> returnServices = route.generateServiceTimetables(getSimulator().getCurrentSimTime(), myScenario, Route.RETURNSTOPS);
                route.generateRouteSchedules(outgoingServices, returnServices);
                //Add route.
                //theRoutes.add(route);
                myScenario.addRoute(route);
            }
            //Sixthly, get the vehicles and create relevant vehicle objects.
            NodeList vehicleList = (NodeList) xpath.evaluate("//scenario/vehicles/vehicle", document.getDocumentElement(), XPathConstants.NODESET);
            for ( int i = 0; i < vehicleList.getLength(); i++ ) {
                Element thisElem = (Element) vehicleList.item(i);
                String[] deliveryDates = thisElem.getAttribute("deliveryDate").split("-");
                Calendar deliveryDate = new GregorianCalendar(Integer.parseInt(deliveryDates[0]), Integer.parseInt(deliveryDates[1])-1, Integer.parseInt(deliveryDates[2]));
                Vehicle myVeh = createVehicleObject(thisElem.getAttribute("id"), thisElem.getAttribute("type"), deliveryDate);
                myVeh.setAssignedSchedule(null);
                myScenario.addVehicle(myVeh);
                //Add allocation to route.
                String schedId = thisElem.getAttribute("route") + "/" + thisElem.getAttribute("schedId");
                for ( int j = 0; j < myScenario.getNumberRoutes(); j++ ) {
                    if ( myScenario.getRoute(j).getRouteNumber().equalsIgnoreCase(thisElem.getAttribute("route")) ) {
                        String[] dates = document.getDocumentElement().getAttribute("time").split("-");
                        String day = dates[2];
                        if ( day.substring(0,1).equalsIgnoreCase("0") ) { day = day.substring(1,2); }
                        myScenario.getRoute(j).addAllocation(schedId, myVeh);
                        break;
                    }
                }
                //logger.debug("Adding vehicle with id " + v.getLast().getVehicleID() + " type " + v.getLast().getVehicleType() + " age " + v.getLast().getVehicleAge());
            }
View Full Code Here

     * @param balance a <code>double</code> with the balance.
     * @param psgSatisfaction a <code>int</code> with the passenger satisfaction.
     * @return a <code>Scenario</code> object.
     */
    public Scenario createScenarioObject ( String scenarioName, String pName, double balance, int psgSatisfaction ) {
        Scenario scenario = null;
      if ( scenarioName.equalsIgnoreCase("Landuff Transport Company") ) {
            scenario = (Scenario) theContext.getBean("LanduffScenario");
        } else if ( scenarioName.equalsIgnoreCase("MDorf Transport Company") ) {
            scenario = (Scenario) theContext.getBean("MDorfScenario");
        } else if ( scenarioName.equalsIgnoreCase("Longts Transport Company") ) {
            scenario = (Scenario) theContext.getBean("LongtsScenario");
        } else {
          return null; //Null if can't find scenario.
        }
        scenario.setPlayerName(pName);
        scenario.setBalance(balance);
        scenario.setPassengerSatisfaction(psgSatisfaction);
        return scenario;
    }
View Full Code Here

TOP

Related Classes of trams.data.Scenario

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.