Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
5d963bef
Commit
5d963bef
authored
Oct 05, 2017
by
Tobias Meuser
Browse files
Pulled Changes from tm/sumo-integration
parents
493642ed
30a32f4c
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/scenario/DefaultConfigurator.java
View file @
5d963bef
...
...
@@ -662,7 +662,7 @@ public class DefaultConfigurator implements Configurator {
}
public
String
parseValue
(
String
value
)
{
if
(
value
.
trim
().
startsWith
(
CONFIG_VARIABLE_PREFIX_TAG
))
{
if
(
value
.
trim
().
startsWith
(
CONFIG_VARIABLE_PREFIX_TAG
)
&&
!
value
.
trim
().
startsWith
(
CONFIG_VARIABLE_PREFIX_TAG
+
"{"
)
)
{
int
posDollar
=
value
.
indexOf
(
CONFIG_VARIABLE_PREFIX_TAG
);
String
varName
=
value
.
substring
(
posDollar
+
1
,
value
.
length
());
value
=
variables
.
get
(
varName
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
View file @
5d963bef
...
...
@@ -331,7 +331,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
freeComponents
.
forEach
((
component
)
->
{
component
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
try
{
RoutedNetLayer
routedNetLayer
=
component
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
...
...
@@ -342,6 +341,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
component
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
});
// Reschedule next step
...
...
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java
View file @
5d963bef
...
...
@@ -14,6 +14,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.simengine.SimulatorObserver
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
...
...
@@ -46,7 +47,7 @@ import de.tudresden.ws.container.SumoPosition2D;
import
de.tudresden.ws.container.SumoStringList
;
import
it.polito.appeal.traci.SumoTraciConnection
;
public
class
TraciSimulationController
implements
VehicleController
,
SimulationSetupExtractor
,
EdgeController
{
public
class
TraciSimulationController
implements
VehicleController
,
SimulationSetupExtractor
,
EdgeController
,
SimulatorObserver
{
private
static
final
File
TEMP_FILE
=
new
File
(
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)),
"road_network.tmp"
);
private
List
<
RoadNetworkEdge
>
modifiedEdges
=
new
ArrayList
<>();
...
...
@@ -105,7 +106,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
// This will only work with the updated version of the TraaS API for sumo
// It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git
_connection
=
new
SumoTraciConnection
(
_sumoExe
,
_configFile
,
random
.
nextInt
());
/*
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/
_connection
.
addOption
(
"time-to-teleport"
,
Integer
.
toString
(-
1
));
try
{
_connection
.
runServer
();
...
...
@@ -118,25 +123,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
e
.
printStackTrace
();
}
Runnable
shutdownHook
=
new
Runnable
()
{
@Override
public
void
run
()
{
_connection
.
close
();
}
};
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
shutdownHook
));
Simulator
.
getInstance
().
addObserver
(
this
);
_initalized
=
true
;
Event
.
scheduleWithDelay
(
Simulator
.
getEndTime
()-
Simulator
.
getCurrentTime
(),
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
_connection
.
close
();
}
},
null
,
0
);
}
}
@Override
public
void
simulationFinished
()
{
/*
* This is called by the simulation scheduler once the simulation is
* finished - it should be used to terminate the connection to SUMO.
*/
if
(
_connection
!=
null
&&
!
_connection
.
isClosed
())
{
_connection
.
close
();
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/views/VisualizationTopologyView.java
View file @
5d963bef
...
...
@@ -43,6 +43,7 @@ import java.util.Collection;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentLinkedQueue
;
import
java.util.concurrent.CopyOnWriteArrayList
;
...
...
@@ -387,7 +388,7 @@ public class VisualizationTopologyView extends JFrame
*/
protected
class
WorldPanel
extends
JLayeredPane
{
protected
HashMap
<
INodeID
,
VisNodeInformation
>
nodeInformation
=
new
HashMap
<
INodeID
,
VisNodeInformation
>();
protected
Concurrent
HashMap
<
INodeID
,
VisNodeInformation
>
nodeInformation
=
new
Concurrent
HashMap
<
INodeID
,
VisNodeInformation
>();
protected
final
static
int
PADDING
=
16
;
...
...
src/de/tud/kom/p2psim/impl/topology/views/visualization/world/NodeInfoComponentVis.java
View file @
5d963bef
...
...
@@ -62,11 +62,13 @@ public class NodeInfoComponentVis extends JComponent
protected
Collection
<
NodeVis
>
nodes
=
new
LinkedList
<>();
private
JMenu
menu
=
new
JMenu
(
"Node Info
rmation
"
);
private
JMenu
menu
=
new
JMenu
(
"Node Info"
);
protected
boolean
[]
activeLayers
=
null
;
boolean
hideInactiveNodes
=
false
;
private
final
String
name
;
public
<
T
extends
HostComponent
>
NodeInfoComponentVis
(
final
Class
<
T
>
componentClass
)
{
...
...
@@ -74,6 +76,8 @@ public class NodeInfoComponentVis extends JComponent
VisualizationInjector
.
getWorldY
());
setOpaque
(
true
);
setVisible
(
true
);
this
.
name
=
componentClass
.
getSimpleName
();
menu
.
setText
(
"Info: "
+
name
);
Event
.
scheduleWithDelay
(
1
*
Time
.
MICROSECOND
,
new
EventHandler
()
{
@Override
...
...
@@ -312,7 +316,7 @@ public class NodeInfoComponentVis extends JComponent
@Override
public
String
getDisplayName
()
{
return
"
Node Information"
;
return
"
Info: "
+
name
;
}
}
src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
View file @
5d963bef
...
...
@@ -48,6 +48,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic
;
import
de.tud.kom.p2psim.impl.util.db.metric.Metric
;
import
de.tud.kom.p2psim.impl.util.db.metric.MetricDescription
;
...
...
@@ -155,6 +156,7 @@ public class DAO {
cfg
.
addAnnotatedClass
(
MeasurementPair
.
class
);
cfg
.
addAnnotatedClass
(
MeasurementPairList
.
class
);
cfg
.
addAnnotatedClass
(
MeasurementSingle
.
class
);
cfg
.
addAnnotatedClass
(
MeasurementSpatial
.
class
);
cfg
.
addAnnotatedClass
(
MeasurementStatistic
.
class
);
cfg
.
addAnnotatedClass
(
Metric
.
class
);
cfg
.
addAnnotatedClass
(
MetricDescription
.
class
);
...
...
src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java
View file @
5d963bef
...
...
@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial
;
import
de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic
;
import
de.tud.kom.p2psim.impl.util.db.metric.Metric
;
import
de.tud.kom.p2psim.impl.util.db.metric.MetricDescription
;
...
...
@@ -101,6 +102,31 @@ public class MeasurementDAO extends DAO {
hostMetric
);
addToPersistQueue
(
measurement
);
}
/**
* Store a single measurement for a host, tied to a specific location.
*
* @param metricDesc
* @param hostId
* @param time
* @param value
* @param locationX
* @param locationY
*/
public
static
void
storeSpatialMeasurement
(
MetricDescription
metricDesc
,
long
hostId
,
long
time
,
double
value
,
int
locationX
,
int
locationY
)
{
if
(
inactive
)
{
return
;
}
Metric
metric
=
MetricDAO
.
lookupSpatialMetric
(
metricDesc
);
HostMetric
hostMetric
=
HostMetricDAO
.
lookupHostMetric
(
metric
,
hostId
);
MeasurementSpatial
measurement
=
new
MeasurementSpatial
(
time
,
value
,
hostMetric
,
locationX
,
locationY
);
addToPersistQueue
(
measurement
);
}
/**
* Stores for a series of measurements the given values for a host. The
...
...
src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java
View file @
5d963bef
...
...
@@ -27,7 +27,7 @@ public class MetricDAO extends DAO {
/**
* Identifier for a single metric
*/
SINGLE
,
SINGLE
,
SPATIAL
,
/**
* Identifier for an aggregate metric
*/
...
...
@@ -62,6 +62,16 @@ public class MetricDAO extends DAO {
public
static
Metric
lookupSingleMetric
(
MetricDescription
metricDesc
)
{
return
lookupMetric
(
metricDesc
,
MetricType
.
SINGLE
);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for spatial value metrics.
*
* If there is no matching Metric object, it is created, persisted, and cached
* automatically.
*/
public
static
Metric
lookupSpatialMetric
(
MetricDescription
metricDesc
)
{
return
lookupMetric
(
metricDesc
,
MetricType
.
SPATIAL
);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for pair value metrics.
...
...
src/de/tud/kom/p2psim/impl/util/db/metric/MeasurementSpatial.java
0 → 100644
View file @
5d963bef
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.util.db.metric
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Index
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.Table
;
/**
* A single measurement, but with an assigned location.
*
* @author Bjoern Richerzhagen
*/
@Entity
@Table
(
name
=
"measurements_spatial"
,
indexes
=
{
@Index
(
columnList
=
"time"
,
name
=
"time"
),
@Index
(
columnList
=
"hostMetricId"
,
name
=
"hostMetricId"
)
})
public
class
MeasurementSpatial
{
/**
* A unique Id, will be set by the database
*/
@SuppressWarnings
(
"unused"
)
@Id
@GeneratedValue
()
private
int
id
;
/**
* The simulation time of this measurement
*/
@SuppressWarnings
(
"unused"
)
private
long
time
;
/**
* The value for this measurement
*/
@SuppressWarnings
(
"unused"
)
@Column
(
nullable
=
true
)
private
Double
value
;
@Column
(
nullable
=
true
,
name
=
"[locationX]"
)
private
Integer
locationX
;
@Column
(
nullable
=
true
,
name
=
"[locationY]"
)
private
Integer
locationY
;
/**
* The mapping Object of this measurement to the {@link Metric}-Object,
* which describes this metric.
*/
@SuppressWarnings
(
"unused"
)
@ManyToOne
@JoinColumn
(
name
=
"hostMetricId"
)
private
HostMetric
hostMetric
;
/**
* Creates a {@link MeasurementSingle}-Object with the given parameters. If
* value has the value infinity or NaN, then will be set this value to null.
*
* @param time
* The simulation time as date to this measurement
* @param value
* The value for this measurement
* @param statistic
* The reference to the {@link Metric}-Object, which describes
* this metric. Is used for the mapping.
*/
public
MeasurementSpatial
(
long
time
,
Double
value
,
HostMetric
hostMetric
,
Integer
locationX
,
Integer
locationY
)
{
super
();
this
.
time
=
time
;
this
.
hostMetric
=
hostMetric
;
// check for infinity or NaN
this
.
value
=
checkForSpecialNumbers
(
value
);
this
.
locationX
=
locationX
;
this
.
locationY
=
locationY
;
}
/**
* Check for special numbers, like infinity or NaN. If the given value is
* equals this numbers then will be return null, otherwise will be returned
* the given value.
*
* @param value
* The value, which should be checked.
* @return The value or null, if it is a special number.
*/
private
Double
checkForSpecialNumbers
(
Double
value
)
{
if
(
value
==
null
)
return
value
;
if
(
value
.
equals
(
Double
.
NEGATIVE_INFINITY
)
||
value
.
equals
(
Double
.
POSITIVE_INFINITY
)
||
value
.
equals
(
Double
.
NaN
))
{
return
null
;
}
else
{
return
value
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment