1
1
package example
2
2
3
+ import org .apache .commons .math3 .distribution .BinomialDistribution
3
4
import tcof ._
4
- import tcof .traits .map2d .{Map2DTrait , Node }
5
+ import tcof .traits .map2d .{Map2DTrait , Node , Position }
5
6
import tcof .traits .statespace .{StateSpaceTrait , interpolate }
6
7
import tcof .traits .statistics .StatisticsTrait
7
8
@@ -18,14 +19,13 @@ class TestScenario extends Universe with Map2DTrait[MapNodeStatus] with StateSpa
18
19
19
20
type MapNode = Node [MapNodeStatus ]
20
21
21
- var noOfStatusMsgReceived = 0
22
- var noOfStatusMsgToBeReceived = 1
23
- var time = 0
22
+ var noOfStatusMsgReceived : Int = _
23
+ var noOfStatusMsgToBeReceived : Int = _
24
24
25
25
def burnModel (node : MapNode ) = interpolate.linear(
26
26
0.0 -> 0.0 ,
27
27
0.5 -> 0.1 ,
28
- 1.0 -> 1 .0
28
+ 1.0 -> 0 .0
29
29
)
30
30
31
31
abstract class MobileUnit extends Component {
@@ -51,20 +51,30 @@ class TestScenario extends Universe with Map2DTrait[MapNodeStatus] with StateSpa
51
51
val routesToBuilding = map.shortestPath.to(building)
52
52
val firePredictor = statespace(burnModel(building), 0 , building.status.burnoutLevel)
53
53
54
+ /*
55
+ println(s"FireFightingTeam for building $building")
56
+ for (c <- components.collect{ case m: MobileUnit => m}) {
57
+ val d = routesToBuilding.costFrom(c.mapPosition).get
58
+ val f = firePredictor.valueAt(d)
59
+ val s = msgDelivery(time - 3600, time).probability > 0.9 withConfidence 0.95
60
+ println(s" ${c} - ${d} - ${f} - ${s}")
61
+ }
62
+ */
63
+
54
64
membership(
55
65
(msgDelivery(time - 3600 , time).probability > 0.9 withConfidence 0.95 ) &&
56
66
57
- allMembers .all(unit => routesToBuilding.costFrom(unit.mapPosition) match {
67
+ fireBrigades .all(unit => routesToBuilding.costFrom(unit.mapPosition) match {
58
68
case None => false
59
69
case Some (travelTime) => firePredictor.valueAt(travelTime) < 0.9
60
70
}) &&
61
71
62
- fireBrigades.cardinality >= 1 && fireBrigades.cardinality <= 3 && ambulances.cardinality === 1
72
+ fireBrigades.cardinality >= 1 && fireBrigades.cardinality <= 3 // && ambulances.cardinality === 1
63
73
)
64
74
65
75
def travelTimeToUtility (routeTime : Option [Double ]) = routeTime match {
66
76
case None => 0
67
- case Some (time) => 100 - ( time / 10000 ).round .toInt
77
+ case Some (time) => 100 - time.toInt
68
78
}
69
79
70
80
utility(
@@ -91,14 +101,62 @@ object TestScenario {
91
101
val scenario = new TestScenario
92
102
scenario.init()
93
103
94
- scenario. components = List (
104
+ val components = List (
95
105
new scenario.FireBrigade (1 ),
96
106
new scenario.FireBrigade (2 ),
97
107
new scenario.FireBrigade (3 ),
98
108
new scenario.AmbulanceTeam (1 ),
99
109
new scenario.AmbulanceTeam (2 )
100
110
)
101
111
112
+ scenario.components = components
113
+
114
+ val mapNodes = new Array [Array [Node [MapNodeStatus ]]](10 )
115
+
116
+ for (x <- 0 until 10 ) {
117
+ mapNodes(x) = new Array [Node [MapNodeStatus ]](10 )
118
+ for (y <- 0 until 10 ) {
119
+ val node = scenario.map.addNode(Position (x, y))
120
+ node.status = new MapNodeStatus (MapNodeKind .Road , false , 0 )
121
+ mapNodes(x)(y) = node
122
+ }
123
+ }
124
+
125
+ for (x <- 1 until 10 ) {
126
+ for (y <- 1 until 10 ) {
127
+ scenario.map.addDirectedEdge(mapNodes(x)(y), mapNodes(x- 1 )(y), 1 )
128
+ scenario.map.addDirectedEdge(mapNodes(x)(y), mapNodes(x)(y- 1 ), 1 )
129
+ scenario.map.addDirectedEdge(mapNodes(x- 1 )(y), mapNodes(x)(y), 1 )
130
+ scenario.map.addDirectedEdge(mapNodes(x)(y- 1 ), mapNodes(x)(y), 1 )
131
+ }
132
+ }
133
+
134
+ val componentMapPositions = List (
135
+ mapNodes(2 )(3 ),
136
+ mapNodes(0 )(8 ),
137
+ mapNodes(1 )(4 ),
138
+ mapNodes(7 )(6 ),
139
+ mapNodes(9 )(2 )
140
+ )
141
+
142
+ components.zip(componentMapPositions).foreach{
143
+ case (component, position) => component.mapPosition = position
144
+ }
145
+
146
+ mapNodes(7 )(2 ).status = new MapNodeStatus (MapNodeKind .Building , true , 0.1 )
147
+ mapNodes(3 )(4 ).status = new MapNodeStatus (MapNodeKind .Building , true , 0.7 )
148
+
149
+
150
+ val trials = 3
151
+ val dist = new BinomialDistribution (trials, 0.91 )
152
+
153
+ scenario.noOfStatusMsgToBeReceived = trials
154
+ for (t <- 0 until 5000 ) {
155
+ scenario.noOfStatusMsgReceived = dist.sample()
156
+ scenario.step(t)
157
+ }
158
+
159
+
102
160
scenario.rootEnsemble.init()
103
161
println(" System initialized" )
104
162
0 commit comments