Skip to content

Commit d3253f2

Browse files
committed
Fix experiment cancelation in first generation of experiment
* The bug was related to the MLC searching to the best individual in a non generations experiment * Also, I add in this commit the sinewave generator used to create sine and cosine waves to burn into the Arduino
1 parent d63bffa commit d3253f2

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

MLC/api/MLCLocal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def get_experiment_info(self, experiment_name):
234234
experiment_info["individuals"] = MLCRepository.get_instance().count_individual()
235235
experiment_info["individuals_per_generation"] = Config.get_instance().getint("POPULATION", "size")
236236

237-
if MLCRepository.get_instance().count_individual() != 0:
237+
if simulation.number_of_generations() != 0:
238238
# Get the best indiv description
239239
min_indiv_id = MLCRepository.get_instance().get_individual_with_min_cost()
240240
min_indiv_data = MLCRepository.get_instance().get_individual_data(min_indiv_id)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding: utf-8 -*-
2+
# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems
3+
# Copyright (C) 2015-2017, Thomas Duriez (thomas.duriez@gmail.com)
4+
# Copyright (C) 2015, Adrian Durán (adrianmdu@gmail.com)
5+
# Copyright (C) 2015-2017, Ezequiel Torres Feyuk (ezequiel.torresfeyuk@gmail.com)
6+
# Copyright (C) 2016-2017, Marco Germano Zbrun (marco.germano@intraway.com)
7+
# Copyright (C) 2016-2017, Raúl Lopez Skuba (raulopez0@gmail.com)
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>
21+
22+
# -*- coding: utf-8 -*-
23+
# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems
24+
# Copyright (C) 2015-2017, Thomas Duriez (thomas.duriez@gmail.com)
25+
# Copyright (C) 2015, Adrian Durán (adrianmdu@gmail.com)
26+
# Copyright (C) 2015-2017, Ezequiel Torres Feyuk (ezequiel.torresfeyuk@gmail.com)
27+
# Copyright (C) 2016-2017, Marco Germano Zbrun (marco.germano@intraway.com)
28+
# Copyright (C) 2016-2017, Raúl Lopez (raulopez@gmail.com)
29+
#
30+
# This program is free software: you can redistribute it and/or modify
31+
# it under the terms of the GNU General Public License as published by
32+
# the Free Software Foundation, either version 3 of the License, or
33+
# (at your option) any later version.
34+
#
35+
# This program is distributed in the hope that it will be useful,
36+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
37+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+
# GNU General Public License for more details.
39+
#
40+
# You should have received a copy of the GNU General Public License
41+
# along with this program. If not, see <http://www.gnu.org/licenses/>
42+
43+
# -*- coding: utf-8 -*-
44+
# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems
45+
# Copyright (C) 2015 Thomas Duriez (thomas.duriez@gmail.com), Adrian Durán (adrianmdu@gmail.com),
46+
# Ezequiel Torres (ezequiel.torresfeyuk@gmail.com), Marco Germano (marco.germano@intraway.com),
47+
# Raul Lopez (raulopez@gmail.com)
48+
49+
# This program is free software: you can redistribute it and/or modify
50+
# it under the terms of the GNU General Public License as published by
51+
# the Free Software Foundation, either version 3 of the License, or
52+
# (at your option) any later version.
53+
54+
# This program is distributed in the hope that it will be useful,
55+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
56+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57+
# GNU General Public License for more details.
58+
59+
# You should have received a copy of the GNU General Public License
60+
# along with this program. If not, see <http://www.gnu.org/licenses/>
61+
import numpy as np
62+
import matplotlib.pyplot as plt
63+
64+
# Sine amplitud
65+
A = 1
66+
# Offset
67+
Offset = 1.6
68+
f0 = 10
69+
w0 = 2 * np.pi * f0
70+
fs = 10e3
71+
72+
n = np.linspace(0, fs, num=fs)
73+
sinewave = Offset + A * np.cos(w0 * n / fs)
74+
75+
dac_max_value = 3800
76+
dac_min_value = 100
77+
78+
# Normalization
79+
min_value = Offset - A
80+
sinewave = (sinewave - min_value) * (dac_max_value - dac_min_value) / 2 + dac_min_value
81+
sinewave = [int(x) for x in sinewave]
82+
83+
fig = plt.figure()
84+
plt.plot(n, sinewave, 'k')
85+
plt.show(block=True)
86+
87+
output = ""
88+
for i in xrange(int(fs)):
89+
if i == 0:
90+
output += "{" + "{0}, ".format(sinewave[i])
91+
if i == (fs - 1):
92+
output += "{0}".format(sinewave[i]) + "}"
93+
else:
94+
output += "{0}, ".format(sinewave[i])
95+
96+
with open("sinewave.txt", "w") as f:
97+
f.write(output)

tests/pocs/test_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>
2121

2222
#from MLC.arduino.connection import MockConnection
23+
import sys
24+
sys.path.append("../..")
2325
from MLC.arduino.connection import SerialConnection
2426
from MLC.arduino.protocol import ArduinoInterface, REPORT_MODES
2527
from MLC.arduino import boards
26-
import sys
2728
import time
2829

2930
def actuate(terminal):

0 commit comments

Comments
 (0)