Commit 7ace069b authored by Jean Meurice's avatar Jean Meurice
Browse files

Master merge

parents 8d1142cb 6c36d896
Pipeline #290758 passed with stage
in 35 seconds
#
# (c) https://github.com/MontiCore/monticore
#
# The license generally applicable for this project
# can be found under https://github.com/MontiCore/monticore.
#
stages:
- windows
......@@ -17,15 +11,6 @@ masterJobLinux:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
only:
- master
masterJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
tags:
- Windows10_OS
only:
- master
BranchJobLinux:
stage: linux
......
# (c) https://github.com/MontiCore/monticore
script:
- git checkout ${TRAVIS_BRANCH}
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report --settings "settings.xml"
......
<a href="https://codeclimate.com/github/MontiSim/commons/maintainability"><img src="https://api.codeclimate.com/v1/badges/1fee5e810477b6a2a432/maintainability" /></a> [![Build Status](https://travis-ci.org/MontiSim/commons.svg?branch=master)](https://travis-ci.org/MontiSim/commons) [![Coverage Status](https://coveralls.io/repos/github/MontiSim/commons/badge.svg?branch=master)](https://coveralls.io/github/MontiSim/commons?branch=master)
# Commons
This repository includes the interfaces and general functionality for the other repositories.
It should be noted that this repository should not have any dependencies on the other repositories - instead all other repositories are allowed to have this repository as dependency.
## JavaFX replacement
## Geometric Types
[Point2D](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Point2D.java), [Point3D](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Point3D.java) and [Pair](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Pair.java) replace the classes of the same name from the JavaFX library.
TODO
## LibraryService
......
<?xml version="1.0" encoding="UTF-8" ?>
<!--
(c) https://github.com/MontiCore/monticore
The license generally applicable for this project
can be found under https://github.com/MontiCore/monticore.
<!--
(c) https://github.com/MontiCore/monticore
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>montisim</groupId>
<artifactId>commons</artifactId>
<version>1.0.11</version>
<version>2.0.0</version>
<properties>
......@@ -79,9 +75,9 @@
</execution>
</executions>
</plugin>
<!-- to add copyright information automatically-->
<plugin>
<!-- <plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>3.0</version>
......@@ -102,8 +98,8 @@
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -143,4 +139,11 @@
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>se-nexus</id>
<name>SE-Nexus repository</name>
<url>https://nexus.se.rwth-aachen.de/content/groups/public</url>
</repository>
</repositories>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
(c) https://github.com/MontiCore/monticore
The license generally applicable for this project
can be found under https://github.com/MontiCore/monticore.
<!--
(c) https://github.com/MontiCore/monticore
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
......
(c) https://github.com/MontiCore/monticore
The license generally applicable for this project
can be found under https://github.com/MontiCore/monticore.
\ No newline at end of file
(c) https://github.com/MontiCore/monticore
\ No newline at end of file
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.composite;
/**
A BusComponent structure represents a tree-like data-set using the Composite Pattern.
The elements can be BusValue, BusComposite or BusArray.
getType() will return the type of the Component.
*/
public interface BusComponent {
enum ComponentType {
VALUE,
ARRAY,
COMPOSITE
}
ComponentType getType();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.composite;
/**
BusValue objects should only content basic data types (double, int, ...).
Complex data types should be represented by BusComposite or BusArray.
*/
public class BusValue implements BusComponent {
private Object value;
public BusValue(Object value){
this.value = value;
}
public void setValue(Object value){
this.value = value;
}
public Object getValue(){
return value;
}
public ComponentType getType(){
return ComponentType.VALUE;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
/**
* Created by lukas on 31.01.17.
*/
public class Adjacency implements IAdjacency{
private IControllerNode node1;
private IControllerNode node2;
private long streetId;
private double distance;
public Adjacency(IControllerNode node1, IControllerNode node2) {
this.node1 = node1;
this.node2 = node2;
this.distance = node1.getPoint().distance(node2.getPoint());
}
@Override
public IControllerNode getNode1() {
return this.node1;
}
@Override
public IControllerNode getNode2() {
return this.node2;
}
@Override
public double getDistance() {
return this.distance;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.utils.Point3D;
import java.util.HashMap;
/**
* Created by lukas on 31.01.17.
*/
public class ControllerNode implements IControllerNode{
private static int counter = 0;
private Point3D p;
private long id;
private long osmId;
private static HashMap<Point3D, Long> ids = new HashMap<>();
public ControllerNode(Point3D p, long osmId) {
this.p = p;
if(!ids.containsKey(p)) {
this.id = ++counter;
ids.put(p, this.id);
} else {
this.id = ids.get(p);
}
this.osmId = osmId;
}
@Override
public Point3D getPoint() {
return this.p;
}
@Override
public long getId() {
return this.id;
}
@Override
public long getOsmId() {
return this.osmId;
}
public String toString() {
return p.toString();
}
public static int getCounter() {
return counter;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
/**
* Created by lukas on 31.01.17.
*/
public interface IAdjacency {
public abstract IControllerNode getNode1();
public abstract IControllerNode getNode2();
public abstract double getDistance();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.utils.Point3D;
/**
* Created by lukas on 31.01.17.
*/
public interface IControllerNode {
public final long INTERPOLATED_NODE = -1;
public final double INTERPOLATION_DISTANCE = 2;
public abstract Point3D getPoint();
public abstract long getId();
public abstract long getOsmId();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation;
import java.time.Instant;
/**
* Interface for a discrete event in a discrete event simulation
*/
public abstract class DiscreteEvent {
/**
* Function that returns the time of the event
*
* @return Time of the event
*/
public abstract Instant getEventTime();
/**
* Function that returns a numeric identifier for the event
*
* @return Numeric identifier for the event
*/
public abstract int getEventId();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
/**
* Abstract class for a discrete event simulation based on scheduled events
* This class implements the SimulationLoopNotifiable interface to be combined with vehicle simulator
*/
public abstract class DiscreteEventSimulator < DiscreteEventType extends DiscreteEvent > extends SimulationLoopNotifiable {
/** Current total time in the discrete event simulation */
private Instant simulationTime = Instant.EPOCH;
/** Last amount of time by which the simulation was advanced */
private Duration lastSimulationDeltaTime = Duration.ZERO;
/** List of discrete events */
private final List<DiscreteEventType> eventList = Collections.synchronizedList(new LinkedList<>());
/** List of simulation notifiable objects */
private final List<DiscreteEventSimulationNotifiable> discreteEventSimulationNotifiableList = Collections.synchronizedList(new LinkedList<>());
/**
* Function that schedules a new event in the discrete event simulation
*
* @param event Event to be scheduled
* @throws IllegalArgumentException when event is timed in the past
*/
public void scheduleEvent(DiscreteEventType event) throws IllegalArgumentException {
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.onScheduleEvent(event);
}
}
// Throw exception if event is in the past
if (event.getEventTime().isBefore(simulationTime)) {
throw new IllegalArgumentException("scheduleEvent: Event is timed in the past! Event: " + event + ", simulationTime: " + simulationTime);
}
// Find correct position in list to add event
int listIndex = 0;
synchronized (eventList) {
for (DiscreteEventType e : eventList) {
// Stop increasing index if event in list is really later than new event
if (e.getEventTime().isAfter(event.getEventTime())) {
break;
}
// Increase index position
listIndex++;
}
}
eventList.add(listIndex, event);
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.afterScheduleEvent(event);
}
}
}
/**
* Function that is called when the discrete simulation time progresses
* Execute all discrete events in order that are in event list before the new total time
*
* @param deltaTime Delta simulation time in nanoseconds
*/
private void advanceSimulationTime(Duration deltaTime) {
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.onAdvanceSimulationTime(deltaTime);
}
}
// Store last delta time value
lastSimulationDeltaTime = deltaTime;
// Store initial time
Instant initialSimulationTime = Instant.from(simulationTime);
// Handle all events that are timed before new simulation time
Instant targetTime = initialSimulationTime.plusNanos(deltaTime.toNanos());
Optional<DiscreteEventType> event = getNextEventInTime(targetTime);
while (event.isPresent()) {
eventList.remove(0);
// Advance time step by step and process event
simulationTime = event.get().getEventTime();
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.onProcessEvent(event.get());
}
}
processEvent(event.get());
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.afterProcessEvent(event.get());
}
}
event = getNextEventInTime(targetTime);
}
// Set simulation time to the end of time advancement
simulationTime = targetTime;
// Inform notifiable objects
synchronized (discreteEventSimulationNotifiableList) {
for (DiscreteEventSimulationNotifiable notifiable : discreteEventSimulationNotifiableList) {
notifiable.afterAdvanceSimulationTime(deltaTime);
}
}
}
/**
* Function that computes the next event that can be executed in simulation time
* Does not return events that are in the future and returns Optional.empty then
*
* @param finalTime Final time before which events should be returned
* @return Next event ready for event handling
*/
private Optional<DiscreteEventType> getNextEventInTime(Instant finalTime) {
Optional<DiscreteEventType> result = Optional.empty();
if (!eventList.isEmpty()) {
DiscreteEventType event = eventList.get(0);
// Check if time of first event matches
if (!event.getEventTime().isAfter(finalTime)) {
result = Optional.of(event);
}
}
// Return computed result
return result;
}
/**
* Function that needs to be implemented in subclasses of DiscreteEventSimulator for processing events
*
* @param event Event to be processed
*/
protected void processEvent(DiscreteEventType event){
}
public void visitEvent(DiscreteEventType event){
}
/**
* Get the current total discrete simulation time
*
* @return Current total discrete simulation time
*/
public Instant getSimulationTime() {
return simulationTime;
}
/**
* Set the current total discrete simulation time
*
* @param simulationTime New total discrete simulation time
*/
protected void setSimulationTime(Instant simulationTime) {
this.simulationTime = simulationTime;
}