소스 검색

AUTHORS; perf sensor; ui improvement

master
Robin Thoni 7 년 전
부모
커밋
56592f7f5e

+ 3
- 0
AUTHORS 파일 보기

@@ -0,0 +1,3 @@
1
+8inf846
2
+THOR16119403 Robin Thoni <robin@rthoni.com>
3
+TIBP18039507 Pierre-Antoine Tible <zhajor@zhajor.com>

+ 1
- 0
README.md 파일 보기

@@ -71,6 +71,7 @@ FakeEnv implementation starts one thread for the environment and another one for
71 71
 
72 72
 Agent logic is in `Agent/*.cs`  
73 73
 Agent sensors and effectors interfaces are in `Agent/Interfaces/*`  
74
+Agent sensors that do not directly rely on physical sensors are in `Agent/Sensors/*.cs`  
74 75
 Agent FakeEnv client implementation is in `Agent/FakeEnv/*`  
75 76
 FakeEnv client, server, protocol and configuration are defined in `Common/*.cs`  
76 77
 FakeEnv server implementation is in `Environment/*.cs`  

+ 5
- 2
uqac-ia-aspirobot/Agent/AgAgent.cs 파일 보기

@@ -9,6 +9,7 @@ using uqac_ia_aspirobot.Agent.FakeEnv.Effectors;
9 9
 using uqac_ia_aspirobot.Agent.FakeEnv.Sensors;
10 10
 using uqac_ia_aspirobot.Agent.Interfaces.Effectors;
11 11
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
12
+using uqac_ia_aspirobot.Agent.Sensors;
12 13
 using uqac_ia_aspirobot.Common;
13 14
 using uqac_ia_aspirobot.Extensions;
14 15
 using uqac_ia_aspirobot.Interfaces;
@@ -44,6 +45,7 @@ namespace uqac_ia_aspirobot.Agent
44 45
             agServices.AddSingleton<IAgBatterySensor, AgBatterySensor>();
45 46
             agServices.AddSingleton<IAgVaccumSensor, AgVaccumSensor>();
46 47
             agServices.AddSingleton<IAgPickedSensor, AgPickedSensor>();
48
+            agServices.AddSingleton<IAgPerformanceSensor, AgPerformanceSensor>();
47 49
 
48 50
             agServices.AddSingleton<IAgVaccumEffector, AgVaccumEffector>();
49 51
             agServices.AddSingleton<IAgEngineEffector, AgEngineEffector>();
@@ -127,13 +129,14 @@ namespace uqac_ia_aspirobot.Agent
127 129
 
128 130
         public void Think()
129 131
         {
130
-            if (_state.LastThinkTime.AddMilliseconds(_state.ThinkTimeInterval) <= DateTime.Now)
132
+            var now = DateTime.Now;
133
+            if (_state.LastThinkTime.AddMilliseconds(_state.ThinkTimeInterval) <= now)
131 134
             {
132 135
                 if (_state.Destination == null && _state.DustyRooms.Any())
133 136
                 {
134 137
                     _state.Destination = _state.DustyRooms.OrderBy(room => room.Distance(_engineEffector)).First();
135 138
                 }
136
-                _state.LastThinkTime = DateTime.Now;
139
+                _state.LastThinkTime = now;
137 140
             }
138 141
         }
139 142
 

+ 13
- 10
uqac-ia-aspirobot/Agent/FakeEnv/AgEnvironment.cs 파일 보기

@@ -10,10 +10,11 @@ namespace uqac_ia_aspirobot.Agent.FakeEnv
10 10
 {
11 11
     public class AgEnvironment : IEnvironment
12 12
     {
13
-        private readonly IAgDustSensor _agDustSensor;
14
-        private readonly IAgBatterySensor _agBatterySensor;
15
-        private readonly IAgPickedSensor _agPickedSensor;
16
-        private readonly IAgVaccumSensor _agVaccumSensor;
13
+        private IAgDustSensor _agDustSensor;
14
+        private IAgBatterySensor _agBatterySensor;
15
+        private IAgPickedSensor _agPickedSensor;
16
+        private IAgVaccumSensor _agVaccumSensor;
17
+        private IAgPerformanceSensor _agPerformanceSensor;
17 18
 
18 19
         private readonly IServiceProvider _serviceProvider;
19 20
 
@@ -25,19 +26,20 @@ namespace uqac_ia_aspirobot.Agent.FakeEnv
25 26
 
26 27
         private readonly IDictionary<string, IRoom> _rooms = new Dictionary<string, IRoom>();
27 28
 
28
-        public AgEnvironment(IServiceProvider serviceProvider, ArClient arClient,
29
-            IAgDustSensor agDustSensor, IAgBatterySensor agBatterySensor, IAgPickedSensor agPickedSensor, IAgVaccumSensor agVaccumSensor)
29
+        public AgEnvironment(IServiceProvider serviceProvider, ArClient arClient)
30 30
         {
31 31
             _serviceProvider = serviceProvider;
32 32
             _arClient = arClient;
33
-            _agDustSensor = agDustSensor;
34
-            _agBatterySensor = agBatterySensor;
35
-            _agPickedSensor = agPickedSensor;
36
-            _agVaccumSensor = agVaccumSensor;
37 33
         }
38 34
 
39 35
         public void Setup()
40 36
         {
37
+            _agDustSensor = _serviceProvider.GetService<IAgDustSensor>();
38
+            _agBatterySensor = _serviceProvider.GetService<IAgBatterySensor>();
39
+            _agPickedSensor = _serviceProvider.GetService<IAgPickedSensor>();
40
+            _agVaccumSensor = _serviceProvider.GetService<IAgVaccumSensor>();
41
+            _agPerformanceSensor = _serviceProvider.GetService<IAgPerformanceSensor>();
42
+
41 43
             _arClient.Setup();
42 44
             _width = _arClient.GetEnvWidth();
43 45
             _height = _arClient.GetEnvWidth();
@@ -65,6 +67,7 @@ namespace uqac_ia_aspirobot.Agent.FakeEnv
65 67
             _agBatterySensor.Update();
66 68
             _agPickedSensor.Update();
67 69
             _agVaccumSensor.Update();
70
+            _agPerformanceSensor.Update();
68 71
         }
69 72
 
70 73
         protected string GetKey(int x, int y)

+ 0
- 8
uqac-ia-aspirobot/Agent/FakeEnv/Sensors/AgDustSensor.cs 파일 보기

@@ -1,17 +1,9 @@
1 1
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
2
-using uqac_ia_aspirobot.Interfaces;
3 2
 
4 3
 namespace uqac_ia_aspirobot.Agent.FakeEnv.Sensors
5 4
 {
6 5
     public class AgDustSensor : IAgDustSensor
7 6
     {
8
-        private readonly AgEnvironment _environment;
9
-
10
-        public AgDustSensor(IEnvironment environment)
11
-        {
12
-            _environment = environment as AgEnvironment;
13
-        }
14
-
15 7
         public void Update()
16 8
         {
17 9
         }

+ 7
- 0
uqac-ia-aspirobot/Agent/Interfaces/Sensors/IAgPerformanceSensor.cs 파일 보기

@@ -0,0 +1,7 @@
1
+namespace uqac_ia_aspirobot.Agent.Interfaces.Sensors
2
+{
3
+    public interface IAgPerformanceSensor : ISensor
4
+    {
5
+        float Performance { get; }
6
+    }
7
+}

+ 34
- 0
uqac-ia-aspirobot/Agent/Sensors/AgPerformanceSensor.cs 파일 보기

@@ -0,0 +1,34 @@
1
+using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
2
+using uqac_ia_aspirobot.Extensions;
3
+using uqac_ia_aspirobot.Interfaces;
4
+
5
+namespace uqac_ia_aspirobot.Agent.Sensors
6
+{
7
+    public class AgPerformanceSensor : IAgPerformanceSensor
8
+    {
9
+        private readonly IAgBatterySensor _agBatterySensor;
10
+
11
+        private readonly IAgPickedSensor _agPickedSensor;
12
+
13
+        private readonly IAgVaccumSensor _agVaccumSensor;
14
+        private readonly IEnvironment _environment;
15
+
16
+        public float Performance { get; protected set; }
17
+
18
+        public AgPerformanceSensor(IAgBatterySensor agBatterySensor, IAgPickedSensor agPickedSensor,
19
+            IAgVaccumSensor agVaccumSensor, IEnvironment environment)
20
+        {
21
+            _agBatterySensor = agBatterySensor;
22
+            _agPickedSensor = agPickedSensor;
23
+            _agVaccumSensor = agVaccumSensor;
24
+            _environment = environment;
25
+        }
26
+
27
+        public void Update()
28
+        {
29
+            var dustyCount = _environment.FindDustyRooms().Count;
30
+            var sum = _agPickedSensor.Picked + _agVaccumSensor.Vaccumed;
31
+            Performance = (_agBatterySensor.Spent == 0 ? 0 : (float)sum / _agBatterySensor.Spent) - dustyCount;
32
+        }
33
+    }
34
+}

+ 7
- 2
uqac-ia-aspirobot/UI/UiConsole.cs 파일 보기

@@ -16,9 +16,10 @@ namespace uqac_ia_aspirobot.UI
16 16
         private readonly IAgBatterySensor _agBatterySensor;
17 17
         private readonly IAgVaccumSensor _agVaccumSensor;
18 18
         private readonly AgState _agState;
19
+        private readonly IAgPerformanceSensor _agPerformanceSensor;
19 20
 
20 21
         public UiConsole(IEnvironment environment, IAgEngineEffector agEngineEffector, IAgPickedSensor agPickedSensor,
21
-            IAgBatterySensor agBatterySensor, IAgVaccumSensor agVaccumSensor, AgState agState)
22
+            IAgBatterySensor agBatterySensor, IAgVaccumSensor agVaccumSensor, AgState agState, IAgPerformanceSensor agPerformanceSensor)
22 23
         {
23 24
             _environment = environment;
24 25
             _agEngineEffector = agEngineEffector;
@@ -26,6 +27,7 @@ namespace uqac_ia_aspirobot.UI
26 27
             _agBatterySensor = agBatterySensor;
27 28
             _agVaccumSensor = agVaccumSensor;
28 29
             _agState = agState;
30
+            _agPerformanceSensor = agPerformanceSensor;
29 31
         }
30 32
 
31 33
         public void SetBackgroundColor(ConsoleColor? color)
@@ -186,10 +188,13 @@ namespace uqac_ia_aspirobot.UI
186 188
                 Console.WriteLine("|");
187 189
             }
188 190
             SetBackgroundColor(bgColor);
191
+            var nextThink = Math.Max(0, (_agState.LastThinkTime.AddMilliseconds(_agState.ThinkTimeInterval) - DateTime.Now).TotalMilliseconds);
189 192
             Console.WriteLine($"Battery: {_agBatterySensor.Spent}");
190 193
             Console.WriteLine($"Vaccumed: {_agVaccumSensor.Vaccumed}");
191 194
             Console.WriteLine($"Picked: {_agPickedSensor.Picked}");
192
-            Console.WriteLine($"Think: {_agState.ThinkTimeInterval}ms");
195
+            Console.WriteLine($"Think Interval: {_agState.ThinkTimeInterval}ms");
196
+            Console.WriteLine($"Next Think: {nextThink}ms");
197
+            Console.WriteLine($"Performance: {_agPerformanceSensor.Performance}");
193 198
         }
194 199
     }
195 200
 }

Loading…
취소
저장