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
d8e40aa1
Commit
d8e40aa1
authored
Oct 09, 2017
by
Tobias Meuser
Committed by
Jose Ignacio Monreal Bailey
Aug 20, 2019
Browse files
Disabled component reuse per default
parent
70547348
Changes
1
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
View file @
d8e40aa1
...
@@ -59,6 +59,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
...
@@ -59,6 +59,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public
class
VehicleMovementModel
implements
MovementModel
,
EventHandler
,
FutureLocationSensor
{
public
class
VehicleMovementModel
implements
MovementModel
,
EventHandler
,
FutureLocationSensor
{
private
boolean
_reuseComponents
=
false
;
private
static
VehicleMovementModel
MOVEMENT
;
private
static
VehicleMovementModel
MOVEMENT
;
public
static
final
double
SCALING_FACTOR
=
1.0
;
public
static
final
double
SCALING_FACTOR
=
1.0
;
...
@@ -153,6 +155,14 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
...
@@ -153,6 +155,14 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
this
.
height
=
height
;
this
.
height
=
height
;
}
}
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
_reuseComponents
=
pReuseComponents
;
if
(
_reuseComponents
)
{
System
.
err
.
println
(
"WARNING: Enabling the reuse of components might cause strange behaviors of your simulation!"
);
}
}
/**
/**
* Adding an additional component to be moved by this movement model
* Adding an additional component to be moved by this movement model
* @param comp The component to be added.
* @param comp The component to be added.
...
@@ -161,6 +171,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
...
@@ -161,6 +171,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
public
final
void
addComponent
(
SimLocationActuator
comp
)
{
public
final
void
addComponent
(
SimLocationActuator
comp
)
{
components
.
add
(
comp
);
components
.
add
(
comp
);
freeComponents
.
add
(
comp
);
freeComponents
.
add
(
comp
);
comp
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
}
}
/**
/**
...
@@ -330,20 +342,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
...
@@ -330,20 +342,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
}
}
}
freeComponents
.
forEach
((
component
)
->
{
try
{
RoutedNetLayer
routedNetLayer
=
component
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
if
(
netInterface
.
isOnline
())
{
netInterface
.
goOffline
();
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
component
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
});
// Reschedule next step
// Reschedule next step
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
0
);
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
0
);
}
}
...
@@ -363,8 +361,23 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
...
@@ -363,8 +361,23 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
// Nothing to do here
// Nothing to do here
}
}
freeComponents
.
add
(
simLocationActuator
);
hostVehicleIDMatching
.
remove
(
simLocationActuator
.
getHost
().
getId
());
hostVehicleIDMatching
.
remove
(
simLocationActuator
.
getHost
().
getId
());
try
{
RoutedNetLayer
routedNetLayer
=
simLocationActuator
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
if
(
netInterface
.
isOnline
())
{
netInterface
.
goOffline
();
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
simLocationActuator
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
if
(
_reuseComponents
)
{
freeComponents
.
add
(
simLocationActuator
);
}
}
}
}
}
}
}
...
@@ -393,7 +406,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
...
@@ -393,7 +406,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
idComponentMatcher
.
put
(
vehicle
,
simLocationActuator
);
idComponentMatcher
.
put
(
vehicle
,
simLocationActuator
);
hostVehicleIDMatching
.
put
(
simLocationActuator
.
getHost
().
getId
(),
vehicle
);
hostVehicleIDMatching
.
put
(
simLocationActuator
.
getHost
().
getId
(),
vehicle
);
}
else
{
}
else
{
throw
new
RuntimeException
(
"Unable to assign new components. Please increase node amount
.
"
);
throw
new
RuntimeException
(
"Unable to assign new components. Please increase node amount"
+
(
_reuseComponents
?
"."
:
" or enable the reuse of components."
)
);
}
}
}
}
return
idComponentMatcher
.
get
(
vehicle
);
return
idComponentMatcher
.
get
(
vehicle
);
...
...
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