Search in sources :

Example 6 with Road

use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.

the class TestDBStatsiticsProvider method testAllFunctions.

/**
 * @Author: Shay
 * @Date: 4/5/18
 * testing DBStatisticsProvider module - with DB
 */
@Test
public void testAllFunctions() {
    BTWDataBaseImpl db = new BTWDataBaseImpl("ShayTest1");
    db.parseMap("{\"type\": \"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]},\"properties\":{\"name\":\"from:1 street section 1R to:1 avenue section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0054000054000054]},\"properties\":{\"name\":\"from:2 street section 1R to:1 avenue section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0054000054000054]},\"properties\":{\"name\":\"from:2 avenue section 1 to:2 avenue section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0]},\"properties\":{\"name\":\"from:1 street section 1 to:1 street section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0054000054000054]},\"properties\":{\"name\":\"from:2 street section 1 to:2 avenue section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0054000054000054]},\"properties\":{\"name\":\"from:2 avenue section 1 to:2 street section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0054000054000054]},\"properties\":{\"name\":\"from:2 street section 1R to:2 street section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0054000054000054]},\"properties\":{\"name\":\"from:1 avenue section 1 to:2 street section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0054000054000054]},\"properties\":{\"name\":\"from:2 street section 1 to:2 street section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]},\"properties\":{\"name\":\"from:1 avenue section 1R to:1 street section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0]},\"properties\":{\"name\":\"from:2 avenue section 1R to:1 street section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0]},\"properties\":{\"name\":\"from:1 street section 1 to:2 avenue section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0054000054000054,0.0]},\"properties\":{\"name\":\"from:2 avenue section 1R to:2 avenue section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]},\"properties\":{\"name\":\"from:1 avenue section 1R to:1 avenue section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]},\"properties\":{\"name\":\"from:1 street section 1R to:1 street section 1\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0054000054000054]},\"properties\":{\"name\":\"from:1 avenue section 1 to:1 avenue section 1R\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0054000054000054,0.0054000054000054],[0.0054000054000054,0.0]]},\"properties\":{\"name\":\"2 avenue section 1R\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[0.0,0.0054000054000054]]},\"properties\":{\"name\":\"1 avenue section 1\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0054000054000054],[0.0,0.0]]},\"properties\":{\"name\":\"1 avenue section 1R\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[0.0054000054000054,0.0]]},\"properties\":{\"name\":\"1 street section 1\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0054000054000054,0.0054000054000054],[0.0,0.0054000054000054]]},\"properties\":{\"name\":\"2 street section 1R\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0054000054000054,0.0],[0.0,0.0]]},\"properties\":{\"name\":\"1 street section 1R\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0054000054000054],[0.0054000054000054,0.0054000054000054]]},\"properties\":{\"name\":\"2 street section 1\",\"length\":\"600\",\"overload\":0}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0054000054000054,0.0],[0.0054000054000054,0.0054000054000054]]},\"properties\":{\"name\":\"2 avenue section 1\",\"length\":\"600\",\"overload\":0}}]}");
    StatisticsProvider sp = new DBStatisticsProvider(db);
    Assert.assertTrue(sp.granularity() == 1800);
    for (Road r : db.getAllRoads()) {
        assertTrue(sp.expectedTimeOnRoadAt(BTWTime.of(0), r).seconds() == 43);
    }
    for (TrafficLight t : db.getAllTrafficLights()) {
        assertTrue(sp.expectedTimeOnTrafficLightAt(BTWTime.of(0), t).seconds() == 0);
    }
    assertNotNull(sp);
}
Also used : DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Road(il.ac.technion.cs.yp.btw.classes.Road) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) StatisticsProvider(il.ac.technion.cs.yp.btw.statistics.StatisticsProvider) Test(org.junit.Test)

Example 7 with Road

use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.

the class TestRoadsDataBase method testGetRoad.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetRoad() {
    String mapName = "first";
    MainDataBase.openConnection();
    Road ayalonn = RoadsDataBase.getRoad("Ayalonn", mapName);
    assertNotNull(ayalonn);
    // System.out.println(ayalonn.toString());
    Road road1 = RoadsDataBase.getRoad("Road1", mapName);
    assertNotNull(road1);
    // System.out.println(road1.toString());
    Road road4 = RoadsDataBase.getRoad("Road4", mapName);
    assertNotNull(road4);
    // System.out.println(road4.toString());
    Road road6 = RoadsDataBase.getRoad("Road6", mapName);
    assertNotNull(road6);
    // System.out.println(road6.toString());
    MainDataBase.closeConnection();
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Test(org.junit.Test)

Example 8 with Road

use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.

the class AbstractNavigationManager method staticAStar.

/**
 * @author Guy Rephaeli
 * @date 26-May-18.
 *
 * A method to perform A* route computation from road 'src' to road 'dst' at time 'time'
 *
 * @param src - the road from which to navigate
 * @param dst -the road to navigate to
 * @param sourceRoadRatio - starting point in the source road
 * @param time - the time to start navigation
 * @return self
 * @throws PathNotFoundException - if a path from src to dst is not found
 */
protected List<Road> staticAStar(Road src, Road dst, double sourceRoadRatio, BTWTime time) throws PathNotFoundException {
    logger.debug("Start A* computation from " + src.getName() + " to " + dst.getName() + " at time " + time.getHoursOnly().toString() + ":" + time.getMinutesOnly().toString() + ":" + time.getSecondsOnly().toString());
    PriorityQueue<RoadWrapper> open = new PriorityQueue<>();
    PriorityQueue<RoadWrapper> closed = new PriorityQueue<>();
    open.add(RoadWrapper.buildSourceRoad(src, dst, sourceRoadRatio, time));
    while (!open.isEmpty()) {
        RoadWrapper next = open.poll();
        closed.add(next);
        if (next.getRoad().equals(dst)) {
            LinkedList<RoadWrapper> path = new LinkedList<>();
            RoadWrapper currWrapper = next;
            while (currWrapper != null) {
                path.addFirst(currWrapper);
                currWrapper = currWrapper.getParent();
            }
            logger.debug("Finished A* computation from " + src.getName() + " to " + dst.getName() + " successfully");
            return path.stream().map(RoadWrapper::getRoad).collect(Collectors.toList());
        }
        for (Road r : next.getNeighbors()) {
            double dist = next.dist + next.getDistFromNeighbor(r);
            RoadWrapper newWrapper = RoadWrapper.buildRouteRoad(r, dst, dist, next, time);
            if (open.contains(newWrapper)) {
                RoadWrapper oldWrapper = null;
                for (RoadWrapper w : open) {
                    if (w.equals(newWrapper)) {
                        oldWrapper = w;
                        break;
                    }
                }
                if (oldWrapper.dist > newWrapper.dist) {
                    open.remove(oldWrapper);
                    open.add(newWrapper);
                }
            } else if (closed.contains(newWrapper)) {
                RoadWrapper oldWrapper = null;
                for (RoadWrapper w : closed) {
                    if (w.equals(newWrapper)) {
                        oldWrapper = w;
                        break;
                    }
                }
                if (oldWrapper.dist > newWrapper.dist) {
                    closed.remove(oldWrapper);
                    open.add(newWrapper);
                }
            } else {
                open.add(newWrapper);
            }
        }
    }
    logger.error("No path found from " + src.getName() + " to " + dst.getName());
    throw new PathNotFoundException("No path from " + src.getName() + " to " + dst.getName());
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road) PriorityQueue(java.util.PriorityQueue) LinkedList(java.util.LinkedList)

Example 9 with Road

use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.

the class VehicleImpl method driveToNextRoad.

/**
 * @author Guy Rephaeli
 *
 * move to the next road on the route
 *
 * @return self
 */
@Override
public Vehicle driveToNextRoad() {
    Road prev = this.currentRoad;
    this.leaveRoad(prev);
    this.isWaitingOnTrafficLight = false;
    this.currentRoad = this.nextRoad;
    if (this.currentRoad.equals(this.destination)) {
        this.nextRoad = null;
        this.driveOnLastRoad();
    } else {
        this.nextRoad = this.navigator.getNextRoad();
        this.driveOnRoad(this.currentRoad);
    }
    return this;
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road)

Example 10 with Road

use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.

the class VehicleImpl method driveOnFirstRoad.

/**
 * @author Guy Rephaeli
 *
 * commit a drive on the first road in the route
 *
 * @return self
 */
public Vehicle driveOnFirstRoad() {
    Road prev = this.currentRoad;
    this.leaveRoad(prev);
    this.isWaitingOnTrafficLight = false;
    this.currentRoad = this.nextRoad;
    if (this.currentRoad.equals(this.destination)) {
        this.nextRoad = null;
        return driveOnRoad(currentRoad, this.sourceRoadRatio, this.destinationRoadRatio);
    }
    this.nextRoad = this.navigator.getNextRoad();
    return driveOnRoad(currentRoad, this.sourceRoadRatio, 1.0);
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road)

Aggregations

Road (il.ac.technion.cs.yp.btw.classes.Road)21 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)10 Test (org.junit.Test)7 Point (il.ac.technion.cs.yp.btw.classes.Point)4 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)4 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)4 HashSet (java.util.HashSet)4 SQLException (java.sql.SQLException)3 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)2 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)2 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)2 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CityCrossroad (il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1