Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies {
//compile 'org.apache.commons:commons-math3:3.6.1'
compile 'com.google.code.gson:gson:2.8.6'


// This dependency is used internally, and not exposed to consumers on their own compile classpath.
testImplementation 'com.google.guava:guava:28.0-jre'
testImplementation 'com.yugabyte:junit:4.12-yb-1'
Expand Down
70 changes: 70 additions & 0 deletions Engine/config/1.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"nodes": [
{
"x": 144.79999999999998,
"y": 231.99999999999997,
"roadsIn": [
1
],
"roadsOut": [
0
]
},
{
"x": 463.2,
"y": 240.79999999999998,
"roadsIn": [
0,
3
],
"roadsOut": [
1,
2
]
},
{
"x": 624.8000000000001,
"y": 172.0,
"roadsIn": [
2
],
"roadsOut": [
3
]
}
],
"roads": [
{
"from": 0,
"to": 1,
"lanes": []
},
{
"from": 1,
"to": 0,
"lanes": [
{
"signs": []
}
]
},
{
"from": 1,
"to": 2,
"lanes": []
},
{
"from": 2,
"to": 1,
"lanes": [
{
"signs": []
}
]
}
],
"pointsOfInterest": [],
"start": "10:00",
"currentTime": "10:15",
"end": "15:00"
}
15 changes: 8 additions & 7 deletions Engine/src/main/java/ru/nsu/team/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.nsu.team;


import ru.nsu.team.controller.SimulationController;

public class Main {
public static void main(String[] args) {
Expand All @@ -9,13 +10,13 @@ public static void main(String[] args) {
return;
}*/

/*SimulationController simulationController = new SimulationController();
simulationController.run("config/sample_2.json");
simulationController.saveRoadMap("config/save1.json");
simulationController.run("config/save1.json");
simulationController.saveRoadMap("config/save2.json");
simulationController.saveCarStates("config/carStates.json");
simulationController.saveHeatMap("config/heatMap.json");*/
// SimulationController simulationController = new SimulationController();
// simulationController.testRun("config/test.tsp");
// simulationController.saveRoadMap("config/save1.json");
// simulationController.testRun("config/save1.json");
// simulationController.saveRoadMap("config/save2.json");
// simulationController.saveCarStates("config/carStates.json");
// simulationController.saveHeatMap("config/heatMap.json");
Master master = new Master();
master.execute(args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ public SimulationController(String mapLoadPath, String heatMapSavePath, String c
this.heatMapSavePath = heatMapSavePath;
this.carStateSavePath = carStateSavePath;
}
public SimulationController() {
}

public void pause() {
}


public void testRun(String path){
RoadMapReader roadMapReader = new RoadMapReader();
this.mapConfig = roadMapReader.getMapConfig(path);
RoadModelCreator mapCreator = new RoadModelCreator();
assert mapConfig != null;
this.roadMap = mapCreator.createRoadMap(mapConfig);
}


private void prepareMap(String fileName) {
RoadMapReader roadMapReader = new RoadMapReader();
this.mapConfig = roadMapReader.getMapConfig(fileName);
Expand Down Expand Up @@ -83,6 +94,10 @@ public void saveHeatMap(String fileName) {
saver.saveHeatMap(reporterBuilder.build(), fileName);
}

public RoadMap getRoadMap() {
return roadMap;
}

@Override
public void run() {
prepareMap(this.mapLoadPath);
Expand Down
20 changes: 18 additions & 2 deletions Engine/src/main/java/ru/nsu/team/entity/roadmap/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ public class Course {
private int length;
private final List<Intersection> intersections;

public Course(Lane fromRoad, Lane toLane) {
this.fromLane = fromRoad;

public Course(Lane fromLane, Lane toLane) {
this.fromLane = fromLane;
this.toLane = toLane;
intersections = new ArrayList<>();
}

public Course(Lane fromLane, Lane toLane, int length) {
this.fromLane = fromLane;
this.toLane = toLane;
this.length = length;
intersections = new ArrayList<>();
}

Expand All @@ -23,6 +31,14 @@ public Course(Lane fromLane, Lane toLane, List<Intersection> intersections, int
this.length = length;
}

public List<Intersection> getIntersections() {
return intersections;
}

public void addIntersection(Intersection intersection) {
this.intersections.add(intersection);
}

public Lane getFromLane() {
return fromLane;
}
Expand Down
9 changes: 8 additions & 1 deletion Engine/src/main/java/ru/nsu/team/entity/roadmap/Lane.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class Lane {
double maxSpeed;
private int laneId;
private Road parentRoad;
private List<TrafficParticipant> trafficParticipants;

Expand All @@ -18,12 +19,18 @@ public Lane(Road parentRoad) {
this.parentRoad = parentRoad;
}

public Lane(double maxSpeed, Road parentRoad) {
public Lane(int laneId,double maxSpeed, Road parentRoad) {
this.laneId = laneId;
this.trafficParticipants = new ArrayList<>();
this.maxSpeed = maxSpeed;
this.parentRoad = parentRoad;
}


public int getLaneId(){
return this.laneId;
}

public List<TrafficParticipant> getParticipants() {
return trafficParticipants;
}
Expand Down
6 changes: 3 additions & 3 deletions Engine/src/main/java/ru/nsu/team/entity/roadmap/Road.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Road(int id, Node from, Node to, int lanes, double maxSpeed) {
this.trafficParticipants = new ArrayList<>();
this.id = id;
for (int i = 0; i < lanes; i++) {
addLane(maxSpeed);
addLane(i, maxSpeed);
}
}

Expand Down Expand Up @@ -101,8 +101,8 @@ public void addLane(Lane lane) {
lanes.add(lane);
}

public void addLane(double maxSpeed) {
lanes.add(new Lane(maxSpeed, this));
public void addLane(int id, double maxSpeed) {
lanes.add(new Lane(id, maxSpeed, this));
}

public Node getFrom() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ru.nsu.team.entity.spawner.Configuration;
import ru.nsu.team.entity.spawner.Spawner;
import ru.nsu.team.entity.trafficparticipant.*;
import ru.nsu.team.other.KeyValuePair;

import java.sql.Time;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -115,22 +115,51 @@ private void createCourses(List<RoadConfiguration> roadsConfig, List<NodeConfigu
List<Integer> outRoadsId = nodeConfig.getRoadsOut();
List<Integer> inRoadsId = nodeConfig.getRoadsIn();
Node node = this.nodes.get(i);

Set<Course> createdCourses = new HashSet<>();
int lenIds = nodeConfig.getCoursesNumber();
for (int heh = 0; heh < lenIds; heh++) {
int in = inRoadsId.get(heh);
for (Lane inLane : roads.get(in).getLanes()) {
for (Integer roadId : outRoadsId) {
roads.get(roadId).getLanes().forEach(outLane -> createdCourses.add(new Course(inLane, outLane, Collections.singletonList(new Intersection(0)), 10)));
//все курсы для одной lane
List<KeyValuePair<Lane, List<Course>>> lanesCourses = new ArrayList<>();
//Set<Course> createdCourses = new HashSet<>();
int coursesNumber = nodeConfig.getCoursesNumber();
for (int inId = 0; inId < coursesNumber; inId++) {
int inRoadId = inRoadsId.get(inId);
for (Lane inLane : roads.get(inRoadId).getLanes()) {
var curCourses = new ArrayList<Course>();
for (Integer outRoadId : outRoadsId) {
roads.get(outRoadId).getLanes().forEach(outLane -> {
//createdCourses.add(new Course(inLane, outLane, 10));
curCourses.add(new Course(inLane, outLane, 10));
});
}
lanesCourses.add(new KeyValuePair<Lane, List<Course>>(inLane, curCourses));
}
}
for (int from = 0; from < lanesCourses.size(); from++) {
var coursesFromLane = lanesCourses.get(from).getValue();
for (Course crFromLane : coursesFromLane) {
for (KeyValuePair<Lane, List<Course>> lanesCours : lanesCourses) {
var anotherLaneCourses = lanesCours.getValue();
for (var cr : anotherLaneCourses) {
if (!haveSameIntersection(crFromLane, cr)) {
var intersection = new Intersection(5);
crFromLane.addIntersection(intersection);
cr.addIntersection(intersection);
}
}
}
}
}
createdCourses.forEach(node::addCourse);
map.getCourseSet().addAll(createdCourses);
lanesCourses.forEach(pair -> pair.getValue().forEach(node::addCourse));
//createdCourses.forEach(node::addCourse);
//map.getCourseSet().addAll(createdCourses);
}
}

private boolean haveSameIntersection(Course f, Course s) {
Set<Intersection> res = new HashSet<>(f.getIntersections());
Set<Intersection> sSet = new HashSet<>(s.getIntersections());
res.retainAll(sSet);
return !res.isEmpty();
}

private void calculateAngles(List<NodeConfiguration> nodeConfigs, List<RoadConfiguration> roadConfigs) {
SortedMap<Double, Road> sm = new TreeMap<Double, Road>();
NodeConfiguration config;
Expand Down Expand Up @@ -158,7 +187,6 @@ private void calculateAngles(List<NodeConfiguration> nodeConfigs, List<RoadConfi
}

private double calculateAngle(NodeConfiguration n1, NodeConfiguration n2, NodeConfiguration n3, NodeConfiguration duplicate) {
assert !n2.equals(duplicate);
double yDif = n3.getY() - n2.getY();

double n2n1X = n1.getX() - n2.getX();
Expand Down
23 changes: 23 additions & 0 deletions Engine/src/test/java/ru/nsu/team/simulator/RoadMapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.nsu.team.simulator;

import org.junit.Test;
import ru.nsu.team.controller.SimulationController;

public class RoadMapTest {
@Test
public void testMapCreation() {
SimulationController simulationController = new SimulationController();
simulationController.testRun("config/1.tsp");
var map = simulationController.getRoadMap();
for (var r : map.getRoads()) {
for (var c : r.getFrom().getCourses()) {
assert c.getIntersections().size() != 0;
}
for (var c : r.getTo().getCourses()) {
assert c.getIntersections().size() != 0;
}
}
}


}
4 changes: 2 additions & 2 deletions Engine/src/test/java/ru/nsu/team/simulator/SimulatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;
import ru.nsu.team.entity.playback.PlaybackBuilder;
import ru.nsu.team.entity.report.ReporterBuilder;
import ru.nsu.team.entity.report.HeatmapBuilder;
import ru.nsu.team.entity.roadmap.*;
import ru.nsu.team.entity.spawner.Configuration;
import ru.nsu.team.entity.spawner.Spawner;
Expand Down Expand Up @@ -71,7 +71,7 @@ private void failTest() {
@Test
public void testSimulator() {
RoadMap rm = createSampleLineRoadMap();
Simulator sim = new Simulator(30, rm, new PlaybackBuilder(), new ReporterBuilder());
Simulator sim = new Simulator(30, rm, new PlaybackBuilder(), new HeatmapBuilder(rm,100));
sim.setUncaughtExceptionHandler((thread, throwable) -> {
throwable.printStackTrace();
failTest();
Expand Down