Examples of ModelManager


Examples of de.hpi.eworld.core.ModelManager

  private static final String DIR_SUMO_TESTRES = "./resources/sumo_test/gen/";
  private static final String RES_FILE_PREFIX = "gen_result";

  @Test
  public void testSumoImport() {
    ModelManager model = ModelManager.getInstance();
    model.clearModel();
    model.notifyObservers(new ObserverNotification(NotificationType.startBatchProcess));
    Sumo2ModelDOM s2m = new Sumo2ModelDOM("./resources/sumo_test/original/berlin_test.net.xml", model, false,
        false, "");
    s2m.run();
   
    model.notifyObservers(new ObserverNotification(NotificationType.endBatchProcess, true, false));

    Assert.assertEquals(1597, ModelManager.getInstance().getAllModelElements().size());
  }
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

    int ways = 0;
    int tls = 0;

    PersistenceManager.getInstance().loadFromFile("./resources/export/berlin_test.ewd");

    ModelManager model = ModelManager.getInstance();

    for (ModelElement el : model.getAllModelElements()) {
      if (el.getClass().equals(NodeModel.class))
        nodes++;
      else if (el.getClass().equals(WayModel.class)) {
        ways++;
        WayModel curWay = (WayModel) el;
        edges += (curWay.getBackwardEdges().size() + curWay.getForwardEdges().size());
      } else if (el.getClass().equals(TrafficLightModel.class))
        tls++;
    }

    System.out.println("ModelElements: " + model.getAllModelElements().size());
    System.out.println("Edges: " + edges);
    System.out.println("Nodes: " + nodes);
    System.out.println("Ways: " + ways);
    System.out.println("TrafficLights: " + tls);

    EWorld2sumo ew2s = new EWorld2sumo();
    ew2s.setData(DIR_SUMO_TESTRES, RES_FILE_PREFIX, true /* doNetconvert */,
        EWorldConstants.getNetConvertFile(), "", true /* doDuarouter */,
        EWorldConstants.getDuaRouterFile(), "", true /* doTlsFile */, false, false,
        false, true, new Integer[]{10000}, false);
    ew2s.run();

    model.clearModel();
    model.notifyObservers(new ObserverNotification(NotificationType.startBatchProcess));
    Sumo2ModelDOM s2m = new Sumo2ModelDOM("./resources/sumo_test/original/berlin_test.net.xml", model, true,
        false, "");
    s2m.run();
    model.notifyObservers(new ObserverNotification(NotificationType.endBatchProcess, true, false));

    int edges2 = 0;
    int nodes2 = 0;
    int ways2 = 0;
    int tls2 = 0;

    for (ModelElement el : model.getAllModelElements()) {
      if (el.getClass().equals(NodeModel.class))
        nodes2++;
      else if (el.getClass().equals(WayModel.class)) {
        ways2++;
        WayModel curWay = (WayModel) el;
        edges2 += (curWay.getBackwardEdges().size() + curWay.getForwardEdges().size());
      } else if (el.getClass().equals(TrafficLightModel.class))
        tls2++;
    }
    System.out.println("ModelElements: " + model.getAllModelElements().size());
    System.out.println("Edges: " + edges2);
    System.out.println("Nodes: " + nodes2);
    System.out.println("Ways: " + ways2);
    System.out.println("TrafficLights: " + tls2);

View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

   * Saves the model element to an ewd file via ModelManager.saveToFile and Loads it afterwards to
   * check if all attributes are restored correctly
   */
  @Test
  public void testSaveAndRestore() {
    ModelManager modelManager = ModelManager.getInstance();
    modelManager.clearModel();

    // save
    modelManager.addModelElement(myWay1);

    PersistenceManager.getInstance().saveToFile(EWD_FILE);

    // restore
    modelManager.clearModel();
    PersistenceManager.getInstance().loadFromFile(EWD_FILE);
    for (ModelElement modelElement : modelManager.getAllModelElements()) {
      WayModel restoredWay1 = (WayModel)modelElement;
      Assert.assertEquals(myWay1.getBackwardEdges().size(), restoredWay1.getBackwardEdges().size());
      Assert.assertEquals(myWay1.getForwardEdges().size(), restoredWay1.getForwardEdges().size());
    }

View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

  public void testSaveAndRestore() {
    NodeModel node = new NodeModel(1., 2.);
    NodeModel helperNode = new NodeModel(2., 3.);
    EdgeModel usedByEdge = TestCaseUtil.createTestEdge(node, helperNode);
   
    ModelManager mm = ModelManager.getInstance();
    //make sure the model is empty before we add anything
    mm.clearModel();
   
    mm.addModelElement(node);
    mm.addModelElement(usedByEdge);
    //save it to an ewd file
    PersistenceManager.getInstance().saveToFile(EWD_FILE);
    //fine, now lets restore the saved objects
    mm.clearModel();
    PersistenceManager.getInstance().loadFromFile(EWD_FILE);
   
    Collection<ModelElement> modelElements = mm.getAllModelElements();
    Iterator<ModelElement> iterator = modelElements.iterator();
    Assert.assertEquals(2, modelElements.size());
    Object obj = iterator.next();
    if(obj instanceof NodeModel) {
      NodeModel restoredNode = (NodeModel) obj;
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

   * prevent endless notification loops between the timeline and the
   * modelmanager. do nothing if the time has not changed.
   */
     if(oldStartTime == time)
       return;
     ModelManager mm = ModelManager.getInstance();
     int endTime = mm.getSimulationEndTime();
     if(time >= endTime)
       startEdit.setText(Integer.toString(oldStartTime));
     else {
       //save new start value
       oldStartTime = time;
  // /* notify modelmanager
  // * DO NOT NOTIFY THE MODELMANAGER BEFORE SAVING THE NEW TIME
  // * INTERNALLY IN oldEndTime. Otherwise this will result in
  // * an endless notification loop (timeline notifying the modelmanager
  // * which in turn notifies all listeners such as the timeline and so on).
  // * the timeline checks if the time change propagated by the modelmanager
  // * actually is a time change at loadTimes().
  // */
       mm.setSimulationStartTime(time);
       timeline.updateSimulationTime();
      
    }
    mainPanel.repaint();
  }
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

      endEdit.setText(Integer.toString(oldEndTime)); //reset to the previous
      // value since the new is invalid
      return;
    }
     
    ModelManager mm = ModelManager.getInstance();
    int startTime = mm.getSimulationStartTime();
  // //check if the new value is valid (must be greater than the starttime!)
    if(time <= startTime)
      endEdit.setText(Integer.toString(oldEndTime)); //reset to the previous
    //value since the new is invalid
    else {
  // //save new end value
      oldEndTime = time;
  // /* notify modelmanager
  // * DO NOT NOTIFY THE MODELMANAGER BEFORE SAVING THE NEW TIME
  // * INTERNALLY IN oldEndTime. Otherwise this will result in
  // * an endless notification loop (timeline notifying the modelmanager
  // * which in turn notifies all listeners such as the timeline and so on).
  // * the timeline checks if the time change propagated by the modelmanager
  // * actually is a time change at loadTimes().
  // */
      mm.setSimulationEndTime(time);
      timeline.updateSimulationTime();
     
    }
    mainPanel.repaint();
  }
 
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

  /**
   * Loads the data for the start and end time widgets from the InternalDB
   */
  public void loadTimes() {
    ModelManager mm = ModelManager.getInstance();
      if( oldStartTime == mm.getSimulationStartTime() &&
        oldEndTime == mm.getSimulationEndTime())
    return; //nothing has changed. prevent endless notification loops
 
    oldStartTime = mm.getSimulationStartTime();
    startEdit.setText(Integer.toString(oldStartTime));
    oldEndTime = mm.getSimulationEndTime();
    endEdit.setText(Integer.toString(oldEndTime));
   
    this.updateStartTime();
    this.updateEndTime();
    mainPanel.repaint();
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

  private static final String DIR_VANET_TESTRES = "./resources/vanet_test/vanet.xml";
 
  @Test
  public void testExportModel() throws ParserConfigurationException, SAXException, FileNotFoundException, IOException {
    //load test data
    ModelManager mm = ModelManager.getInstance();
    //use mm mockup to count the element occurences for export verification
    ModelManagerMockUp mmMockUp = ModelManagerMockUp.getInstance();
    mmMockUp.convertWaysToEdges();
    mm.addObserver(mmMockUp);
    //ok, now actually load the .ewd file
   
    PersistenceManager.getInstance().loadFromFile("./resources/export/berlin_test.ewd");

    //start export
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

   
   
    ///////////////////////////////////
    // run restore test
   
    ModelManager mm = ModelManager.getInstance();
   
    //make sure the model is empty before we add anything
    mm.clearModel();
   
    mm.addModelElement(el1);
    mm.addModelElement(el2);
    mm.addModelElement(pl);
    mm.addModelElement(cl);
   
    //save it to an ewd file
    PersistenceManager.getInstance().saveToFile(EWD_FILE);
   
    //fine, now lets restore the saved objects
    mm.clearModel();
    PersistenceManager.getInstance().loadFromFile(EWD_FILE);
   
    Collection<ModelElement> modelElements = mm.getAllModelElements();
    Assert.assertEquals(4, modelElements.size());

    //cleanup
    Assert.assertTrue(FileSysUtils.deleteFile(EWD_FILE));
  }
View Full Code Here

Examples of de.hpi.eworld.core.ModelManager

    areas.add(startArea2);
    vehicleCountPerArea.put(startArea1, new int[] { 50, 0 });
    vehicleCountPerArea.put(startArea2, new int[] { 10, 0 });

    // add all created areas to model manager
    ModelManager modelManager = ModelManager.getInstance();
    //modelManager.clearModel();
    for (AreaModel area : areas) {
      modelManager.addModelElement(area);
    }

    // export to sumo
    EWorld2sumo eWorld2sumo = new EWorld2sumo();
    eWorld2sumo.setData(DIRECTORY_SCENARIOS_TEST, FILE_SCENARIOS_TEST_PREFIX, true, EWorldConstants.getNetConvertFile(), "",
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.