Search in sources :

Example 1 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 2 with Road

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

the class QueryTrafficLightExample method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Override
public Set<Road> arrangeRecievedData(ResultSet resultSet) {
    Set<Road> roads = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            int cord1x = resultSet.getInt("cord1x");
            int cord2x = resultSet.getInt("cord2x");
            int cord1y = resultSet.getInt("cord1y");
            int cord2y = resultSet.getInt("cord2y");
            int length = resultSet.getInt("length");
            int secStart = resultSet.getInt("secStart");
            int secEnd = resultSet.getInt("secEnd");
            String overload = resultSet.getString("overload");
            System.out.println("nameID = " + nameID + " cord1x = " + cord1x + " cord2x = " + cord2x + " cord1y = " + cord1y + " cord2y = " + cord2y + " length = " + length + " secStart = " + secStart + " secEnd = " + secEnd + " overload = " + overload);
            String myStreet = nameID.split("st")[0];
            Point sourceCrossroadId = new PointImpl(cord1x, cord1y);
            Point destinationCrossroadId = new PointImpl(cord2x, cord2y);
            Road road = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, mapName);
            System.out.println(road.toString());
            roads.add(road);
        }
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return roads;
}
Also used : SQLException(java.sql.SQLException) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Road(il.ac.technion.cs.yp.btw.classes.Road) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Point(il.ac.technion.cs.yp.btw.classes.Point) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 3 with Road

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

the class NaiveNavigationManager method staticAStar.

private List<Road> staticAStar(Road src, Road dst, double sourceRoadRatio) throws PathNotFoundException {
    PriorityQueue<RoadWrapper> open = new PriorityQueue<>();
    PriorityQueue<RoadWrapper> closed = new PriorityQueue<>();
    open.add(RoadWrapper.buildSourceRoad(src, dst, sourceRoadRatio));
    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();
            }
            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);
            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);
            }
        }
    }
    throw new PathNotFoundException("No path from " + src.getRoadName() + " to " + dst.getRoadName());
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road) PriorityQueue(java.util.PriorityQueue) LinkedList(java.util.LinkedList)

Example 4 with Road

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

the class DataStreet method toString.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * get a string represents the street*/
@Override
public String toString() {
    String street = "";
    street += "street: ";
    street += "name = " + name;
    street += "\nthe roads are:\n";
    for (Road road : roads) {
        street += "\t" + road.toString() + "\n";
    }
    return street;
}
Also used : Road(il.ac.technion.cs.yp.btw.classes.Road)

Example 5 with Road

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

the class MapGraphics method calculateTrafficLightLocation.

/**
 *@author: Anat & Sharon
 * @date: 20/1/18
 * returns the degree value in radians
 * of the given line on, from the x-axis
 * @param trafficLight - the line we check is its source road
 * @return the degree value in radians
 *         of the given line on, from the x-axis
 *         The functions:
 *         y1 = ax+b1
 *         y2 = -(1/a)*x+b2
 */
private Point calculateTrafficLightLocation(TrafficLight trafficLight) {
    Road sourceRoad = trafficLight.getSourceRoad();
    double deviationAngle = 0.85;
    double deviationDistance = 0.0003;
    return getDeviationFromVectorEnd(sourceRoad.getSourceCrossroad(), sourceRoad.getDestinationCrossroad(), deviationAngle, deviationDistance);
}
Also used : CityRoad(il.ac.technion.cs.yp.btw.citysimulation.CityRoad) Road(il.ac.technion.cs.yp.btw.classes.Road)

Aggregations

Road (il.ac.technion.cs.yp.btw.classes.Road)14 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)8 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)5 Point (il.ac.technion.cs.yp.btw.classes.Point)4 SQLException (java.sql.SQLException)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 BTWWeight (il.ac.technion.cs.yp.btw.classes.BTWWeight)1 DataStreet (il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet)1 Query (il.ac.technion.cs.yp.btw.db.queries.Query)1 ResultSet (java.sql.ResultSet)1 LinkedList (java.util.LinkedList)1 PriorityQueue (java.util.PriorityQueue)1 Set (java.util.Set)1 TestResult (junit.framework.TestResult)1 DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)1 SimpleDirectedWeightedGraph (org.jgrapht.graph.SimpleDirectedWeightedGraph)1