@@ -9,9 +9,9 @@ GiandujaBeaconAggregationLoopFunction::GiandujaBeaconAggregationLoopFunction() {
9
9
m_cCoordSpot2 = CVector2 (-0.5 ,0.5 );
10
10
m_unCostSpot1 = 0 ;
11
11
m_fObjectiveFunction = 0 ;
12
- m_Tbar = 0 ;
13
- m_State = 0 ;
14
12
m_unTime = 0 ;
13
+ m_unMesParam = 0 ;
14
+ m_unMes = 0 ;
15
15
}
16
16
17
17
/* ***************************************/
@@ -36,23 +36,37 @@ void GiandujaBeaconAggregationLoopFunction::Reset() {
36
36
CoreLoopFunctions::Reset ();
37
37
m_unCostSpot1 = 0 ;
38
38
m_fObjectiveFunction = 0 ;
39
- m_State = 0 ;
40
- m_Tbar = 0 ;
41
- m_unTime = 0 ;
42
- ExtractTime ();
39
+ if (m_unMesParam == 3 ) {
40
+ m_unMes = m_pcRng->Uniform (CRange<UInt32>(0 ,2 ));
41
+ }
42
+ else {
43
+ m_unMes = m_unMesParam;
44
+ }
43
45
PlaceBeacon ();
44
46
// PlaceLight();
45
47
}
46
48
47
49
48
50
void GiandujaBeaconAggregationLoopFunction::Init (TConfigurationNode& t_tree) {
49
51
CoreLoopFunctions::Init (t_tree);
52
+ TConfigurationNode cParametersNode;
53
+ try {
54
+ cParametersNode = GetNode (t_tree, " params" );
55
+ GetNodeAttributeOrDefault (cParametersNode, " mes" , m_unMesParam, (UInt32) 3 );
56
+ } catch (std::exception e) {
57
+ LOGERR << e.what () << std::endl;
58
+ }
59
+ if (m_unMesParam == 3 ) {
60
+ m_unMes = m_pcRng->Uniform (CRange<UInt32>(0 ,2 ));
61
+ }
62
+ else {
63
+ m_unMes = m_unMesParam;
64
+ }
50
65
// PlaceLight();
51
- ExtractTime ();
52
66
PlaceBeacon ();
67
+ SetMessageBeacon ();
53
68
}
54
69
55
-
56
70
/* ***************************************/
57
71
/* ***************************************/
58
72
@@ -71,19 +85,6 @@ argos::CColor GiandujaBeaconAggregationLoopFunction::GetFloorColor(const argos::
71
85
return CColor::GRAY50;
72
86
}
73
87
74
-
75
- void GiandujaBeaconAggregationLoopFunction::ExtractTime () {
76
- try {
77
- CEPuckEntity& cEntity = dynamic_cast <CEPuckEntity&>(GetSpace ().GetEntity (" beacon0" ));
78
- CEPuckBeacon& cController = dynamic_cast <CEPuckBeacon&>(cEntity.GetControllableEntity ().GetController ());
79
- m_Tbar = cController.getTBar ();
80
- // LOG << "Time=" << m_Tbar << std::endl;
81
- } catch (std::exception& ex) {
82
- LOGERR << " Error while casting ExtractTime: " << ex.what () << std::endl;
83
- }
84
- }
85
-
86
-
87
88
void GiandujaBeaconAggregationLoopFunction::PlaceBeacon () {
88
89
try {
89
90
CEPuckEntity& cEpuck = dynamic_cast <CEPuckEntity&>(GetSpace ().GetEntity (" beacon0" ));
@@ -97,22 +98,16 @@ void GiandujaBeaconAggregationLoopFunction::PlaceBeacon() {
97
98
98
99
}
99
100
100
- // void GiandujaBeaconAggregationLoopFunction::PlaceLight() {
101
- // // /* Place a light at a random spot to prevent robots to exploit (anti)phototaxis behaviours as RW */
102
- // CLightEntity& cLight = dynamic_cast<CLightEntity&>(GetSpace().GetEntity("light0"));
103
- // /* Consider the light only if it has non zero intensity */
104
- // cLight.SetIntensity(m_pcRng->Uniform(CRange<Real>(0.05f, 0.8f)));
105
- //
106
- // Real ab;
107
- // Real DistributionRadius = 1.3;
108
- //
109
- // ab = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
110
- // Real posX = DistributionRadius * cos(2 * CRadians::PI.GetValue() * ab);
111
- // Real posY = DistributionRadius * sin(2 * CRadians::PI.GetValue() * ab);
112
- //
113
- // cLight.MoveTo(CVector3(posX, posY, 0.4),CQuaternion().FromEulerAngles(m_pcRng->Uniform(CRange<CRadians>(CRadians::ZERO,CRadians::TWO_PI)),
114
- // CRadians::ZERO,CRadians::ZERO));
115
- // }
101
+ void GiandujaBeaconAggregationLoopFunction::SetMessageBeacon () {
102
+ try {
103
+ CEPuckEntity& cEntity = dynamic_cast <CEPuckEntity&>(GetSpace ().GetEntity (" beacon0" ));
104
+ CEPuckBeacon& cController = dynamic_cast <CEPuckBeacon&>(cEntity.GetControllableEntity ().GetController ());
105
+ cController.setMessage (m_unMes);
106
+ // LOG << "Time=" << m_Tbar << std::endl;
107
+ } catch (std::exception& ex) {
108
+ LOGERR << " Error while casting SetMessageBeacon: " << ex.what () << std::endl;
109
+ }
110
+ }
116
111
117
112
CVector3 GiandujaBeaconAggregationLoopFunction::GetRandomPosition () {
118
113
Real a;
@@ -134,22 +129,21 @@ void GiandujaBeaconAggregationLoopFunction::PostStep() {
134
129
CSpace::TMapPerType& tEpuckMap = GetSpace ().GetEntitiesByType (" epuck" );
135
130
CVector2 cEpuckPosition (0 ,0 );
136
131
137
- if (m_unTime > m_Tbar) {
138
- m_State = 1 ;
139
- }
140
-
141
132
for (CSpace::TMapPerType::iterator it = tEpuckMap.begin (); it != tEpuckMap.end (); ++it) {
142
133
CEPuckEntity* pcEpuck = any_cast<CEPuckEntity*>(it->second );
143
134
cEpuckPosition.Set (pcEpuck->GetEmbodiedEntity ().GetOriginAnchor ().Position .GetX (),
144
135
pcEpuck->GetEmbodiedEntity ().GetOriginAnchor ().Position .GetY ());
145
136
146
- Real fDistanceSpot1 = (m_cCoordSpot1 - cEpuckPosition).Length ();
147
-
148
- if (m_State == 0 && fDistanceSpot1 <= m_fRadius) {
149
- m_unCostSpot1 += 2 ;
137
+ Real fDistanceSpot ;
138
+ if (m_unMes == 0 ) {
139
+ fDistanceSpot = (m_cCoordSpot1 - cEpuckPosition).Length ();
150
140
}
151
- else if (m_State == 1 && fDistanceSpot1 >= m_fRadius) {
152
- m_unCostSpot1 += 2 ;
141
+ else if (m_unMes == 1 ) {
142
+ fDistanceSpot = (m_cCoordSpot2 - cEpuckPosition).Length ();
143
+ }
144
+
145
+ if (fDistanceSpot >= m_fRadius) {
146
+ m_unCostSpot1 += 1 ;
153
147
}
154
148
}
155
149
m_fObjectiveFunction = (Real) m_unCostSpot1;
@@ -165,9 +159,6 @@ void GiandujaBeaconAggregationLoopFunction::PostExperiment() {
165
159
166
160
Real GiandujaBeaconAggregationLoopFunction::GetObjectiveFunction () {
167
161
SInt32 score = 24000 -m_fObjectiveFunction;
168
- if (score < 0 ) {
169
- score = 0 ;
170
- }
171
162
return (score);
172
163
}
173
164
0 commit comments