Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
ebcc5236
Commit
ebcc5236
authored
May 28, 2021
by
Yann Boucher
Browse files
Merge branch 'master' of
https://gitlab.utc.fr/lo21_pin_noir_boucher_bouri_detree/cellulutlo21
parents
1ec54fa3
85468808
Pipeline
#78767
passed with stages
in 17 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/automaton.hpp
View file @
ebcc5236
...
...
@@ -12,23 +12,30 @@ Cette classe représente un automate cellulaire.
#include
"neighborhoodrule.hpp"
#include
"transitionrule.hpp"
#include
"grid.h"
#include
"alphabet.hpp"
//! \brief Représente une configuration d'un automate à un instant t : ses règles de voisinage et transition et son réseau.
class
Automaton
{
private:
Alphabet
alphabet
;
Grid
grid
;
NeighborhoodRule
*
neighbourhoodRule
;
TransitionRule
*
transitionRule
;
Grid
grid
;
public:
Automaton
(
NeighborhoodRule
*
,
TransitionRule
*
,
const
Grid
&
=
Grid
(
0
,
0
)
);
Automaton
();
virtual
~
Automaton
();
//! \brief Fait avancer l'automate à l'état suivant
void
runOnce
();
void
setAlphabet
(
const
Alphabet
&
);
void
setNeighborhoodRule
(
NeighborhoodRule
*
);
NeighborhoodRule
*
getNeighborhoodRule
()
const
;
void
setTransitionRule
(
TransitionRule
*
);
TransitionRule
*
getTransitionRule
()
const
;
void
setCell
(
const
Coord
&
,
unsigned
int
);
const
Grid
&
getGrid
()
const
;
void
setGrid
(
const
Grid
&
);
const
Grid
&
getGrid
()
const
{
return
grid
;}
void
setGrid
(
const
Grid
&
g
)
{
grid
=
g
;}
void
runOnce
();
};
#endif // AUTOMATON_HPP
include/interface.hpp
View file @
ebcc5236
...
...
@@ -8,6 +8,7 @@
#include
<QFileDialog>
#include
"property.hpp"
#include
"simulation.hpp"
class
Structure
;
...
...
@@ -95,5 +96,6 @@ private:
QJsonObject
default_model
()
const
;
private:
Ui
::
MainWindow
*
ui
;
Simulation
simulation
;
};
#endif // MAINWINDOW_HPP
include/neighborhoodrule.hpp
View file @
ebcc5236
...
...
@@ -37,6 +37,7 @@ struct NeighborhoodFormat
class
NeighborhoodRule
:
public
HasUserProperties
{
public:
virtual
~
NeighborhoodRule
()
=
default
;
//! \brief Retourne l'ensemble des voisins d'une cellule de position 'pos' sur la grille 'grid' sous la forme d'une structure 'Neighborhood'
//! \return L'ensemble des voisins de la cellule à 'pos'
virtual
Neighborhood
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
=
0
;
...
...
include/simulation.hpp
View file @
ebcc5236
...
...
@@ -15,6 +15,7 @@ Cette classe représente un automate cellulaire dans le temps.
class
Simulation
{
private:
bool
canRun
;
int
time
;
Automaton
automaton
;
Grid
startGrid
;
...
...
@@ -23,7 +24,14 @@ private:
public:
Simulation
();
virtual
~
Simulation
();
void
setAutomaton
(
const
Automaton
&
);
void
setNeighborhoodRule
(
NeighborhoodRule
*
);
void
setTransitionRule
(
TransitionRule
*
);
void
setAlphabet
(
const
Alphabet
&
);
const
Grid
&
getGrid
()
const
;
void
setCell
(
const
Coord
&
,
unsigned
int
);
void
resize
(
size_t
,
size_t
);
void
reset
();
void
step
();
void
back
();
...
...
src/automaton.cpp
View file @
ebcc5236
#include
"automaton.hpp"
Automaton
::
Automaton
(
NeighborhoodRule
*
n
,
TransitionRule
*
t
,
const
Grid
&
g
)
:
neighbourhoodRule
(
n
),
transitionRule
(
t
),
grid
(
Grid
(
g
)
)
{}
Automaton
::
Automaton
(
)
:
alphabet
(),
grid
(
0
,
0
),
neighbourhoodRule
(
n
ullptr
),
transitionRule
(
nullptr
)
{}
Automaton
::~
Automaton
()
{
delete
neighbourhoodRule
;
delete
transitionRule
;
}
void
Automaton
::
runOnce
(
)
{
Grid
tempGrid
(
grid
)
;
for
(
int
i
=
0
;
i
<
grid
.
get_rows
();
++
i
)
{
for
(
int
j
=
0
;
j
<
grid
.
get_col
();
++
j
)
{
tempG
rid
.
set_cell
({
i
,
j
},
transitionRule
->
getState
(
grid
.
get_state
({
i
,
j
}),
neighbourhoodRule
->
getNeighborhood
(
grid
,
{
i
,
j
}))
);
void
Automaton
::
setAlphabet
(
const
Alphabet
&
A
)
{
alphabet
=
A
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
grid
.
get_rows
()
)
;
++
i
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
grid
.
get_col
()
)
;
++
j
)
{
g
rid
.
set_cell
({
i
,
j
},
0
);
}
}
neighbourhoodRule
->
step
();
for
(
int
i
=
0
;
i
<
grid
.
get_rows
();
++
i
)
{
for
(
int
j
=
0
;
j
<
grid
.
get_col
();
++
j
)
{
grid
=
tempGrid
;
}
void
Automaton
::
setNeighborhoodRule
(
NeighborhoodRule
*
NR
)
{
delete
neighbourhoodRule
;
neighbourhoodRule
=
NR
;
}
NeighborhoodRule
*
Automaton
::
getNeighborhoodRule
()
const
{
return
neighbourhoodRule
;
}
void
Automaton
::
setTransitionRule
(
TransitionRule
*
TR
)
{
delete
transitionRule
;
transitionRule
=
TR
;
}
TransitionRule
*
Automaton
::
getTransitionRule
()
const
{
return
transitionRule
;
}
void
Automaton
::
setCell
(
const
Coord
&
coord
,
unsigned
int
val
)
{
grid
.
set_cell
(
coord
,
val
%
alphabet
.
taille
());
}
const
Grid
&
Automaton
::
getGrid
()
const
{
return
grid
;
}
void
Automaton
::
setGrid
(
const
Grid
&
G
)
{
grid
=
G
;
unsigned
int
state
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
grid
.
get_rows
());
++
i
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
grid
.
get_col
());
++
j
)
{
state
=
grid
.
get_state
({
i
,
j
});
if
(
state
>=
alphabet
.
taille
())
{
grid
.
set_cell
({
i
,
j
},
state
%
alphabet
.
taille
());
}
}
}
}
void
Automaton
::
runOnce
()
{
Grid
tempGrid
(
grid
);
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
grid
.
get_rows
());
++
i
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
grid
.
get_col
());
++
j
)
{
tempGrid
.
set_cell
({
i
,
j
},
transitionRule
->
getState
(
grid
.
get_state
({
i
,
j
}),
neighbourhoodRule
->
getNeighborhood
(
grid
,
{
i
,
j
}))
%
alphabet
.
taille
());
}
}
grid
=
tempGrid
;
}
src/interface.cpp
View file @
ebcc5236
...
...
@@ -14,6 +14,7 @@
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
)
,
ui
(
new
Ui
::
MainWindow
)
,
simulation
()
{
ui
->
setupUi
(
this
);
...
...
src/simulation.cpp
View file @
ebcc5236
#include
"simulation.hpp"
Simulation
::
Simulation
()
:
automaton
(
nullptr
,
nullptr
),
hist
(
10
),
startGrid
(
0
,
0
),
time
(
0
)
{
//ctor
Simulation
::
Simulation
()
:
canRun
(
false
),
time
(
0
),
automaton
(),
startGrid
(
0
,
0
),
hist
(
10
)
{}
Simulation
::~
Simulation
()
{}
void
Simulation
::
setNeighborhoodRule
(
NeighborhoodRule
*
NR
)
{
canRun
=
false
;
automaton
.
setNeighborhoodRule
(
NR
);
}
Simulation
::
~
Simulation
()
{
//dtor
void
Simulation
::
setTransitionRule
(
TransitionRule
*
TR
)
{
canRun
=
false
;
automaton
.
setTransitionRule
(
TR
);
}
void
Simulation
::
setAutomaton
(
const
Automaton
&
A
)
{
automaton
=
A
;
startGrid
=
automaton
.
getGrid
();
time
=
0
;
hist
=
History
(
10
);
void
Simulation
::
setAlphabet
(
const
Alphabet
&
A
)
{
automaton
.
setAlphabet
(
A
);
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
startGrid
.
get_rows
());
++
i
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
startGrid
.
get_col
());
++
j
)
{
startGrid
.
set_cell
({
i
,
j
},
0
);
}
}
}
const
Grid
&
Simulation
::
getGrid
()
const
{
return
automaton
.
getGrid
();
}
void
Simulation
::
setCell
(
const
Coord
&
coord
,
unsigned
int
val
)
{
automaton
.
setCell
(
coord
,
val
);
startGrid
.
set_cell
(
coord
,
val
);
}
void
Simulation
::
resize
(
size_t
l
,
size_t
c
)
{
Grid
newGrid
(
l
,
c
);
int
min
=
static_cast
<
int
>
(
startGrid
.
get_rows
()
<=
l
?
startGrid
.
get_rows
()
:
l
);
int
max
=
static_cast
<
int
>
(
startGrid
.
get_col
()
<=
c
?
startGrid
.
get_col
()
:
c
);
for
(
int
i
=
0
;
i
<
min
;
++
i
)
{
for
(
int
j
=
0
;
j
<
max
;
++
j
)
{
newGrid
.
set_cell
({
i
,
j
},
startGrid
.
get_state
({
i
,
j
}));
}
}
startGrid
=
newGrid
;
reset
();
}
void
Simulation
::
reset
()
{
...
...
@@ -26,11 +56,15 @@ void Simulation::reset() {
void
Simulation
::
step
()
{
hist
.
pushGrid
(
automaton
.
getGrid
());
automaton
.
runOnce
();
automaton
.
getNeighborhoodRule
()
->
step
();
++
time
;
}
void
Simulation
::
back
()
{
automaton
.
setGrid
(
hist
.
topGrid
());
hist
.
popGrid
();
--
time
;
if
(
hist
.
isEmpty
())
{
automaton
.
setGrid
(
hist
.
topGrid
());
//automaton.getNeighborhoodRule()->back();
hist
.
popGrid
();
--
time
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment