コード例 #1
0
ファイル: CTCellTest.java プロジェクト: matsim-org/matsim
 public void testGetXY() throws Exception {
   CTCell c = getCTLinkCell();
   double x = c.getX();
   double y = c.getY();
   assertEquals("x-coordinate", 42d, x);
   assertEquals("y-coordinate", 24d, y);
 }
コード例 #2
0
ファイル: CTCellTest.java プロジェクト: matsim-org/matsim
 public void testSetArea() throws Exception {
   CTCell c = getCTLinkCell();
   c.setArea(1234);
   double a = c.getAlpha();
   assertEquals("correct area", 1234d, a);
   //		c.getA
 }
コード例 #3
0
ファイル: CTCellTest.java プロジェクト: matsim-org/matsim
 public void testAddNeighbor() throws Exception {
   CTCell c = getCTLinkCell();
   CTCell nb = getCTLinkCell();
   c.addNeighbor(nb);
   List<CTCell> nbs = c.getNeighbors();
   assertEquals("number of neighbors", 1, nbs.size());
   assertEquals("same neighbor", nb, nbs.iterator().next());
 }
コード例 #4
0
ファイル: CTCellTest.java プロジェクト: matsim-org/matsim
 public void testAddGetFace() throws Exception {
   CTCell c = getCTLinkCell();
   CTCellFace face = new CTCellFace(0, 0, 1, 1, null, 1);
   c.addFace(face);
   List<CTCellFace> faces = c.getFaces();
   assertEquals("number of faces", 1, faces.size());
   assertEquals("same face", face, faces.iterator().next());
 }
コード例 #5
0
ファイル: Debugger2.java プロジェクト: matsim-org/matsim
  public static void main(String[] args) {

    CTRunner.DEBUG = true;

    Config c = ConfigUtils.createConfig();

    c.global().setCoordinateSystem("EPSG:3395");
    Scenario sc = ScenarioUtils.createScenario(c);

    createNetwork(sc);
    EventsManagerImpl em = new EventsManagerImpl();

    if (CTRunner.DEBUG) {
      //			Sim2DConfig conf2d = Sim2DConfigUtils.createConfig();
      //			Sim2DScenario sc2d = Sim2DScenarioUtils.createSim2dScenario(conf2d);
      //
      //
      //			sc.addScenarioElement(Sim2DScenario.ELEMENT_NAME, sc2d);
      EventBasedVisDebuggerEngine dbg = new EventBasedVisDebuggerEngine(sc);
      InfoBox iBox = new InfoBox(dbg, sc);
      dbg.addAdditionalDrawer(iBox);
      //		dbg.addAdditionalDrawer(new Branding());
      QSimDensityDrawer qDbg = new QSimDensityDrawer(sc);
      dbg.addAdditionalDrawer(qDbg);

      em.addHandler(qDbg);
      em.addHandler(dbg);
    }

    CTNetwork net = new CTNetwork(sc.getNetwork(), em, null);
    double coeff = 0.05;
    int nrPeds = 0;
    {
      CTLink link = net.getLinks().get(Id.createLinkId("0"));
      List<Id<Link>> links = new ArrayList<>();
      links.add(Id.createLinkId(0));
      links.add(Id.createLinkId(1));
      links.add(Id.createLinkId(2));
      links.add(Id.createLinkId(3));
      for (CTCell cell : link.getCells()) {

        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("r" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("1"));
      List<Id<Link>> links = new ArrayList<>();

      links.add(Id.createLinkId(1));
      links.add(Id.createLinkId(2));
      links.add(Id.createLinkId(3));
      links.add(Id.createLinkId(0));
      for (CTCell cell : link.getCells()) {

        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("r" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("2"));
      List<Id<Link>> links = new ArrayList<>();

      links.add(Id.createLinkId(2));
      links.add(Id.createLinkId(3));
      links.add(Id.createLinkId(0));
      links.add(Id.createLinkId(1));
      for (CTCell cell : link.getCells()) {

        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("r" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("3"));
      List<Id<Link>> links = new ArrayList<>();

      links.add(Id.createLinkId(3));
      links.add(Id.createLinkId(0));
      links.add(Id.createLinkId(1));
      links.add(Id.createLinkId(2));
      for (CTCell cell : link.getCells()) {

        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("r" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("4"));
      List<Id<Link>> links = new ArrayList<>();

      links.add(Id.createLinkId(4));
      links.add(Id.createLinkId(7));
      links.add(Id.createLinkId(6));
      links.add(Id.createLinkId(5));
      for (CTCell cell : link.getCells()) {
        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("b" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("5"));
      List<Id<Link>> links = new ArrayList<>();

      links.add(Id.createLinkId(5));
      links.add(Id.createLinkId(4));
      links.add(Id.createLinkId(7));
      links.add(Id.createLinkId(6));
      for (CTCell cell : link.getCells()) {
        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("b" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("6"));
      List<Id<Link>> links = new ArrayList<>();
      links.add(Id.createLinkId(6));
      links.add(Id.createLinkId(5));
      links.add(Id.createLinkId(4));
      links.add(Id.createLinkId(7));
      for (CTCell cell : link.getCells()) {
        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("b" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    {
      CTLink link = net.getLinks().get(Id.createLinkId("7"));
      List<Id<Link>> links = new ArrayList<>();
      links.add(Id.createLinkId(7));
      links.add(Id.createLinkId(6));
      links.add(Id.createLinkId(5));
      links.add(Id.createLinkId(4));
      for (CTCell cell : link.getCells()) {
        int n = cell.getN();
        int rnd =
            (int)
                (n
                    * coeff
                    * MatsimRandom.getRandom()
                        .nextDouble()); /// 4;//n/3;//(int)
                                        // (MatsimRandom.getRandom().nextInt(n)*.5);
        for (int i = 0; i < rnd; i++) {

          DriverAgent walker = new SimpleCTNetworkWalker(links, Id.createPersonId("b" + nrPeds++));

          CTPed ped = new CTPed(cell, walker);
          cell.jumpOnPed(ped, 0);
        }
        cell.updateIntendedCellJumpTimeAndChooseNextJumper(0);
      }
    }
    System.out.println(nrPeds);
    long start = System.nanoTime();
    net.run();
    long stop = System.nanoTime();
    System.out.println("sim took:" + ((stop - start) / 1000. / 1000.) + " ms");
    //		LineSegment ls = new LineSegment();
    //		ls.x0 = 0;
    //		ls.x1 = 0;
    //		ls.y1 = 0;
    //		ls.x1 = -10;
    //		LineEvent le = new LineEvent(0,ls,true,0,128,128,255,0);
    //		em.processEvent(le);

  }