Skip to content

Commit 03180d2

Browse files
committed
New aggregation loopfunctions for Antoine
1 parent 541bd2b commit 03180d2

10 files changed

+530
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include(${CMAKE_SOURCE_DIR}/src/cmake/ARGoSBuildChecks.cmake)
2929
# Set base source files
3030
#
3131
add_subdirectory(src)
32-
32+
add_subdirectory(manual-controllers)
3333

3434
if(ARGOS_BUILD_FOR_SIMULATOR)
3535
add_subdirectory(loop-functions)

loop-functions/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ link_directories(
77

88
#add_subdirectory(chocolate)
99
#add_subdirectory(example)
10-
add_subdirectory(gianduja)
10+
#add_subdirectory(gianduja)
11+
add_subdirectory(complexity)
1112
add_subdirectory(vanilla)
13+
add_subdirectory(extra)
1214
add_subdirectory(visual-add-ons)
15+
#add_subdirectory(debug)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* @file <loop-functions/AggregationTwoSpotsLoopFunc.cpp>
3+
*
4+
* @author Antoine Ligot - <[email protected]>
5+
*
6+
* @license MIT License
7+
*/
8+
9+
#include "AggregationSingleSpot.h"
10+
11+
/****************************************/
12+
/****************************************/
13+
14+
AggregationSingleSpot::AggregationSingleSpot() {
15+
m_fRadius = 0.3;
16+
m_cCoordSpot1 = CVector2(0,0);
17+
m_unScoreSpot1 = 0;
18+
m_fObjectiveFunction = 0;
19+
}
20+
21+
/****************************************/
22+
/****************************************/
23+
24+
AggregationSingleSpot::AggregationSingleSpot(const AggregationSingleSpot& orig) {}
25+
26+
/****************************************/
27+
/****************************************/
28+
29+
void AggregationSingleSpot::Init(TConfigurationNode& t_tree) {
30+
CoreLoopFunctions::Init(t_tree);
31+
}
32+
33+
/****************************************/
34+
/****************************************/
35+
36+
37+
AggregationSingleSpot::~AggregationSingleSpot() {}
38+
39+
/****************************************/
40+
/****************************************/
41+
42+
void AggregationSingleSpot::Destroy() {}
43+
44+
/****************************************/
45+
/****************************************/
46+
47+
argos::CColor AggregationSingleSpot::GetFloorColor(const argos::CVector2& c_position_on_plane) {
48+
CVector2 vCurrentPoint(c_position_on_plane.GetX(), c_position_on_plane.GetY());
49+
Real d = (m_cCoordSpot1 - vCurrentPoint).Length();
50+
if (d <= m_fRadius) {
51+
return CColor::BLACK;
52+
}
53+
54+
return CColor::GRAY50;
55+
}
56+
57+
58+
/****************************************/
59+
/****************************************/
60+
61+
void AggregationSingleSpot::Reset() {
62+
m_fObjectiveFunction = 0;
63+
m_unScoreSpot1 = 0;
64+
CoreLoopFunctions::Reset();
65+
}
66+
67+
/****************************************/
68+
/****************************************/
69+
70+
void AggregationSingleSpot::PostExperiment() {
71+
CSpace::TMapPerType& tEpuckMap = GetSpace().GetEntitiesByType("epuck");
72+
CVector2 cEpuckPosition(0,0);
73+
for (CSpace::TMapPerType::iterator it = tEpuckMap.begin(); it != tEpuckMap.end(); ++it) {
74+
CEPuckEntity* pcEpuck = any_cast<CEPuckEntity*>(it->second);
75+
cEpuckPosition.Set(pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetX(),
76+
pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetY());
77+
78+
Real fDistanceSpot1 = (m_cCoordSpot1 - cEpuckPosition).Length();
79+
if (fDistanceSpot1 <= m_fRadius) {
80+
m_unScoreSpot1 += 1;
81+
}
82+
}
83+
84+
m_fObjectiveFunction = m_unScoreSpot1/(Real) m_unNumberRobots;
85+
LOG << "Score = " << m_fObjectiveFunction << std::endl;
86+
}
87+
88+
/****************************************/
89+
/****************************************/
90+
91+
Real AggregationSingleSpot::GetObjectiveFunction() {
92+
return m_fObjectiveFunction;
93+
}
94+
95+
/****************************************/
96+
/****************************************/
97+
98+
CVector3 AggregationSingleSpot::GetRandomPosition() {
99+
Real temp;
100+
Real a = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
101+
Real b = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
102+
// If b < a, swap them
103+
if (b < a) {
104+
temp = a;
105+
a = b;
106+
b = temp;
107+
}
108+
Real fPosX = b * m_fDistributionRadius * cos(2 * CRadians::PI.GetValue() * (a/b));
109+
Real fPosY = b * m_fDistributionRadius * sin(2 * CRadians::PI.GetValue() * (a/b));
110+
111+
return CVector3(fPosX, fPosY, 0);
112+
}
113+
114+
REGISTER_LOOP_FUNCTIONS(AggregationSingleSpot, "aggregation_single");
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
*
3+
* @author Antoine Ligot - <[email protected]>
4+
*
5+
* @package ARGoS3-AutoMoDe
6+
*
7+
* @license MIT License
8+
*/
9+
10+
#ifndef AGGREGATION_SINGLE_SPOT
11+
#define AGGREGATION_SINGLE_SPOT
12+
13+
#include <argos3/core/simulator/space/space.h>
14+
#include <argos3/plugins/robots/e-puck/simulator/epuck_entity.h>
15+
16+
#include "../../src/CoreLoopFunctions.h"
17+
18+
using namespace argos;
19+
20+
class AggregationSingleSpot: public CoreLoopFunctions {
21+
public:
22+
AggregationSingleSpot();
23+
AggregationSingleSpot(const AggregationSingleSpot& orig);
24+
virtual ~AggregationSingleSpot();
25+
26+
virtual void Destroy();
27+
virtual void Init(TConfigurationNode& t_tree);
28+
29+
virtual argos::CColor GetFloorColor(const argos::CVector2& c_position_on_plane);
30+
virtual void PostExperiment();
31+
virtual void Reset();
32+
33+
Real GetObjectiveFunction();
34+
35+
CVector3 GetRandomPosition();
36+
37+
private:
38+
Real m_fRadius;
39+
CVector2 m_cCoordSpot1;
40+
41+
UInt32 m_unScoreSpot1;
42+
Real m_fObjectiveFunction;
43+
};
44+
45+
#endif
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* @file <loop-functions/AggregationTwoSpotsLoopFunc.cpp>
3+
*
4+
* @author Antoine Ligot - <[email protected]>
5+
*
6+
* @license MIT License
7+
*/
8+
9+
#include "AggregationTwoSpots5050.h"
10+
11+
/****************************************/
12+
/****************************************/
13+
14+
AggregationTwoSpots5050::AggregationTwoSpots5050() {
15+
m_fRadius = 0.3;
16+
m_cCoordSpot1 = CVector2(0.5,0);
17+
m_cCoordSpot2 = CVector2(-0.5,0);
18+
m_unScoreSpot1 = 0;
19+
m_unScoreSpot2 = 0;
20+
m_fObjectiveFunction = 0;
21+
}
22+
23+
/****************************************/
24+
/****************************************/
25+
26+
AggregationTwoSpots5050::AggregationTwoSpots5050(const AggregationTwoSpots5050& orig) {}
27+
28+
/****************************************/
29+
/****************************************/
30+
31+
void AggregationTwoSpots5050::Init(TConfigurationNode& t_tree) {
32+
CoreLoopFunctions::Init(t_tree);
33+
}
34+
35+
/****************************************/
36+
/****************************************/
37+
38+
39+
AggregationTwoSpots5050::~AggregationTwoSpots5050() {}
40+
41+
/****************************************/
42+
/****************************************/
43+
44+
void AggregationTwoSpots5050::Destroy() {}
45+
46+
/****************************************/
47+
/****************************************/
48+
49+
argos::CColor AggregationTwoSpots5050::GetFloorColor(const argos::CVector2& c_position_on_plane) {
50+
CVector2 vCurrentPoint(c_position_on_plane.GetX(), c_position_on_plane.GetY());
51+
Real d = (m_cCoordSpot1 - vCurrentPoint).Length();
52+
if (d <= m_fRadius) {
53+
return CColor::BLACK;
54+
}
55+
56+
d = (m_cCoordSpot2 - vCurrentPoint).Length();
57+
if (d <= m_fRadius) {
58+
return CColor::BLACK;
59+
}
60+
61+
return CColor::GRAY50;
62+
}
63+
64+
65+
/****************************************/
66+
/****************************************/
67+
68+
void AggregationTwoSpots5050::Reset() {
69+
m_fObjectiveFunction = 0;
70+
m_unScoreSpot1 = 0;
71+
m_unScoreSpot2 = 0;
72+
CoreLoopFunctions::Reset();
73+
}
74+
75+
/****************************************/
76+
/****************************************/
77+
78+
void AggregationTwoSpots5050::PostExperiment() {
79+
CSpace::TMapPerType& tEpuckMap = GetSpace().GetEntitiesByType("epuck");
80+
CVector2 cEpuckPosition(0,0);
81+
for (CSpace::TMapPerType::iterator it = tEpuckMap.begin(); it != tEpuckMap.end(); ++it) {
82+
CEPuckEntity* pcEpuck = any_cast<CEPuckEntity*>(it->second);
83+
cEpuckPosition.Set(pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetX(),
84+
pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetY());
85+
86+
Real fDistanceSpot1 = (m_cCoordSpot1 - cEpuckPosition).Length();
87+
Real fDistanceSpot2 = (m_cCoordSpot2 - cEpuckPosition).Length();
88+
if (fDistanceSpot1 <= m_fRadius) {
89+
m_unScoreSpot1 += 1;
90+
} else if (fDistanceSpot2 <= m_fRadius){
91+
m_unScoreSpot2 += 1;
92+
}
93+
}
94+
95+
m_fObjectiveFunction = Min(m_unScoreSpot1, m_unScoreSpot2)/((Real) m_unNumberRobots/2);
96+
LOG << "Score = " << m_fObjectiveFunction << std::endl;
97+
}
98+
99+
/****************************************/
100+
/****************************************/
101+
102+
Real AggregationTwoSpots5050::GetObjectiveFunction() {
103+
return m_fObjectiveFunction;
104+
}
105+
106+
/****************************************/
107+
/****************************************/
108+
109+
CVector3 AggregationTwoSpots5050::GetRandomPosition() {
110+
Real temp;
111+
Real a = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
112+
Real b = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
113+
// If b < a, swap them
114+
if (b < a) {
115+
temp = a;
116+
a = b;
117+
b = temp;
118+
}
119+
Real fPosX = b * m_fDistributionRadius * cos(2 * CRadians::PI.GetValue() * (a/b));
120+
Real fPosY = b * m_fDistributionRadius * sin(2 * CRadians::PI.GetValue() * (a/b));
121+
122+
return CVector3(fPosX, fPosY, 0);
123+
}
124+
125+
REGISTER_LOOP_FUNCTIONS(AggregationTwoSpots5050, "aggregation_5050");
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
*
3+
* @author Antoine Ligot - <[email protected]>
4+
*
5+
* @package ARGoS3-AutoMoDe
6+
*
7+
* @license MIT License
8+
*/
9+
10+
#ifndef AGGREGATION_TWO_SPOTS_50_50
11+
#define AGGREGATION_TWO_SPOTS_50_50
12+
13+
#include <argos3/core/simulator/space/space.h>
14+
#include <argos3/plugins/robots/e-puck/simulator/epuck_entity.h>
15+
16+
#include "../../src/CoreLoopFunctions.h"
17+
18+
using namespace argos;
19+
20+
class AggregationTwoSpots5050: public CoreLoopFunctions {
21+
public:
22+
AggregationTwoSpots5050();
23+
AggregationTwoSpots5050(const AggregationTwoSpots5050& orig);
24+
virtual ~AggregationTwoSpots5050();
25+
26+
virtual void Destroy();
27+
virtual void Init(TConfigurationNode& t_tree);
28+
29+
virtual argos::CColor GetFloorColor(const argos::CVector2& c_position_on_plane);
30+
virtual void PostExperiment();
31+
virtual void Reset();
32+
33+
Real GetObjectiveFunction();
34+
35+
CVector3 GetRandomPosition();
36+
37+
private:
38+
Real m_fRadius;
39+
CVector2 m_cCoordSpot1;
40+
CVector2 m_cCoordSpot2;
41+
42+
UInt32 m_unScoreSpot1;
43+
UInt32 m_unScoreSpot2;
44+
Real m_fObjectiveFunction;
45+
};
46+
47+
#endif

0 commit comments

Comments
 (0)