création de measure/list.c et de measure/manage.c (+ struct m_pile in fsm.h)
This commit is contained in:
parent
d2af43dcc9
commit
9e0ef7d28f
|
@ -44,14 +44,14 @@ enum fsm_select_STORE_RESTORE_RESET { STORE, RESTORE, RESET };
|
||||||
|
|
||||||
enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME };
|
enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME };
|
||||||
|
|
||||||
typedef struct pile // 1er essai : measures (2024-08-26)
|
typedef struct m_pile // 1er essai : measures (2024-08-26)
|
||||||
{
|
{
|
||||||
int value; // to replace
|
int value; // to replace
|
||||||
int measure_type;
|
int measure_type;
|
||||||
int *at_rule; // réserve un emplacement pour stocker une adresse mémoire.
|
int *p_rule; // réserve un emplacement pour stocker une adresse mémoire.
|
||||||
// at_rule = &rule; < écrira l'adresse de rule dans cet emplacement.
|
// at_rule = &rule; < écrira l'adresse de rule dans cet emplacement.
|
||||||
struct pile *prev;
|
struct m_pile *prev;
|
||||||
} pile;
|
} m_pile;
|
||||||
|
|
||||||
#define n_rules 128 // arbitrary
|
#define n_rules 128 // arbitrary
|
||||||
#define n_objects 32 // arbitrary too,
|
#define n_objects 32 // arbitrary too,
|
||||||
|
@ -59,7 +59,7 @@ typedef struct pile // 1er essai : measures (2024-08-26)
|
||||||
|
|
||||||
void fsm_init(); // def: fsm/dispatch; call: main;
|
void fsm_init(); // def: fsm/dispatch; call: main;
|
||||||
void fsm_preferences_init(); // def: fsm/prefer; call: fsm/dispatch;
|
void fsm_preferences_init(); // def: fsm/prefer; call: fsm/dispatch;
|
||||||
void fsm_measures_list_init(); // def: fsm/measure; call: fsm/dispatch;
|
void fsm_measures_list_init(); // def: fsm/measure/list.c; call: fsm/dispatch;
|
||||||
void fsm_results_list_init(); // def: fsm/results; call: fsm/dispatch;
|
void fsm_results_list_init(); // def: fsm/results; call: fsm/dispatch;
|
||||||
void fsm_displayable_list_init(); // def: fsm/prefer; call: fsm/dispatch;
|
void fsm_displayable_list_init(); // def: fsm/prefer; call: fsm/dispatch;
|
||||||
|
|
||||||
|
@ -77,7 +77,8 @@ bool fsm_get_preferences_state(); // def: fsm/dispatch; call: - - -
|
||||||
void fsm_set_preferences_state (bool value); // def: fsm/dispatch; call: signal;
|
void fsm_set_preferences_state (bool value); // def: fsm/dispatch; call: signal;
|
||||||
// fsm/prefer;
|
// fsm/prefer;
|
||||||
|
|
||||||
void fsm_add_measure (char *measure_name); // def: fsm/measure; call: widget/measure/dispatch;
|
void fsm_add_measure (char *measure_name); // def: fsm/measure/manage.c;
|
||||||
|
// call: widget/measure/dispatch;
|
||||||
void fsm_add_result (char *result_name); // def: fsm/result; call: - - -
|
void fsm_add_result (char *result_name); // def: fsm/result; call: - - -
|
||||||
void fsm_add_displayable (char *displayable_name);// def: fsm/prefer; call: fsm/prefer;
|
void fsm_add_displayable (char *displayable_name);// def: fsm/prefer; call: fsm/prefer;
|
||||||
|
|
||||||
|
@ -90,3 +91,7 @@ void fsm_debug_msg (int choice, int value, char *string, int sub_automaton);
|
||||||
// fsm/measure;
|
// fsm/measure;
|
||||||
// fsm/result;
|
// fsm/result;
|
||||||
|
|
||||||
|
int fsm_pile_push (m_pile **p, int val); // def: measure/list call measure/list
|
||||||
|
int fsm_pile_pop (m_pile **p); // def: measure/list call measure/list
|
||||||
|
void fsm_pile_view (m_pile *p); // def: measure/list call measure/list
|
||||||
|
int fsm_pile_length (m_pile *p); // def: measure/list call measure/list
|
||||||
|
|
|
@ -51,12 +51,7 @@ char *util_read_file (char *filename);
|
||||||
// Est bien sûr autorisé tout ce qui concerne les logiciels gratuits, freewares et évaluation.
|
// Est bien sûr autorisé tout ce qui concerne les logiciels gratuits, freewares et évaluation.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// typedef struct pile {int value; struct pile *prev;} pile; // structure d'un élément
|
typedef struct pile {int value; struct pile *prev;} pile; // structure d'un élément
|
||||||
// LE TYPE 'pile' EST REDÉFINI DANS fsm.h ET UTILISÉ DANS fsm/measure.c
|
|
||||||
|
|
||||||
// 2024-08-26 J'avais - trop vite ! - imaginé des piles ou listes génériques, mais
|
|
||||||
// en fait, chaque structure sera très typée et très spécifique
|
|
||||||
// (des règles, groupes de règles, objets, dates, durées, etc.)
|
|
||||||
|
|
||||||
void util_pile_clear (pile **); // vide toute la pile
|
void util_pile_clear (pile **); // vide toute la pile
|
||||||
void util_pile_view (pile *); // affiche la pile en commençant par le sommet
|
void util_pile_view (pile *); // affiche la pile en commençant par le sommet
|
||||||
|
@ -88,6 +83,7 @@ int util_sorted_list_length (slist *sl); // renvoie le nombre d'él
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void util_trigger_test(); // def: util/tests.c calls: ...
|
||||||
void util_pile_test(); // called in fsm/measure.c
|
void util_pile_test(); // called in fsm/measure.c
|
||||||
void util_double_list_test(); // " "
|
void util_double_list_test(); // " "
|
||||||
void util_sorted_list_test(); // " "
|
void util_sorted_list_test(); // " "
|
||||||
|
|
|
@ -0,0 +1,154 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Gem-graph client *
|
||||||
|
* *
|
||||||
|
* State machine *
|
||||||
|
* *
|
||||||
|
* Copyright © 2024 Libre en Communs <contact@a-lec.org> *
|
||||||
|
* Copyright © 2024 Adrien Bourmault <neox@a-lec.org> *
|
||||||
|
* Copyright © 2024 Jean Sirmai <jean@a-lec.org> *
|
||||||
|
* *
|
||||||
|
* This file is part of Gem-graph. *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify it *
|
||||||
|
* under the terms of the GNU Affero General Public License *
|
||||||
|
* as published by the Free Software Foundation, *
|
||||||
|
* either version 3 of the License, *
|
||||||
|
* or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; *
|
||||||
|
* without even the implied warranty of MERCHANTABILITY *
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU Affero General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Affero General Public License *
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "../../../include/fsm.h"
|
||||||
|
#include "../../../include/util.h"
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FFFFFFFFFFF SSSSS MM MM */
|
||||||
|
/* FF SSS SS MMMM MMMM */
|
||||||
|
/* FF SS MM MM MM MM */
|
||||||
|
/* FFFFFFF SS MM MM MM MM */
|
||||||
|
/* FF SS MM MM MM */
|
||||||
|
/* FF SSS MM MM */
|
||||||
|
/* FF SS SSS MM MM */
|
||||||
|
/* FF SSSSSS MM MM */
|
||||||
|
/* */
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* Each state of the finite state machine (fsm) must be */
|
||||||
|
/* - saved at the end of a work session and */
|
||||||
|
/* - reread (available) at the start of a new session. */
|
||||||
|
/* */
|
||||||
|
/* No state of the fsm should be defined in another module. */
|
||||||
|
/* No fsm transition needs to be executed in another module. */
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* M E A S U R E M E N T S */
|
||||||
|
/******************************************************************************/
|
||||||
|
// An editable list of measurements is defined and maintained here.
|
||||||
|
// Each possible measurement can be activated or silenced.
|
||||||
|
|
||||||
|
// The measures relate to
|
||||||
|
// - the number of occurrences of a rule or group of rules,
|
||||||
|
// - the number of objects or situations before/after the rule was applied,
|
||||||
|
// - the time (date) of the event,
|
||||||
|
// - the time elapsed between two events,
|
||||||
|
// - the occurrence of events C between events A and B
|
||||||
|
// - (non limitative, maybe) < pattern recognition tools ?
|
||||||
|
|
||||||
|
// When a list of measurements is established, it is possible to evaluate
|
||||||
|
// if the results of a measurement are correlated with some other results.
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// structure de données : chaque "item" comportera :
|
||||||
|
|
||||||
|
// - identifiant (clé) (+/- pointeur vers : date de création, auteur,...)
|
||||||
|
|
||||||
|
// - type de mesure
|
||||||
|
// les 6 items suivants peuvent documenter l'ensemble de toutes les valeurs
|
||||||
|
// à recueillir pour documenter tous les types de mesure possibles;
|
||||||
|
// tous ces items ne doivent pas être simultanément complétés
|
||||||
|
// mais, si un tableau etait utilisé, il y aurait peu de place perdue;
|
||||||
|
|
||||||
|
// - pointeur vers le premier groupe de règles (une au moins)
|
||||||
|
// - pointeur vers un second groupe de règles (une au moins)
|
||||||
|
// - pointeur vers des objets ou situations (un au moins)
|
||||||
|
// - pointeur vers un ensemble d'évènements intercurrents
|
||||||
|
// - date de l'évènement
|
||||||
|
// - durée entre deux évènements
|
||||||
|
|
||||||
|
// - mesure active ? + / -
|
||||||
|
// - pointeur vers une liste de mesures similaires
|
||||||
|
// - pointeur vers des données, des représentations de données ?
|
||||||
|
|
||||||
|
|
||||||
|
void fsm_measures_list_init ()
|
||||||
|
{
|
||||||
|
m_pile *exemple = NULL; // doit être initialisée à NULL
|
||||||
|
printf ("fsm push > %d\n", fsm_pile_push (&exemple, 4));
|
||||||
|
fsm_pile_view (exemple);
|
||||||
|
printf ("fsm pop > %d\n", fsm_pile_pop (&exemple));
|
||||||
|
fsm_pile_view (exemple);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsm_pile_push (m_pile **p, int val)
|
||||||
|
{
|
||||||
|
m_pile *element = malloc (sizeof(m_pile));
|
||||||
|
if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué.
|
||||||
|
element->value = val;
|
||||||
|
element->prev = *p;
|
||||||
|
*p = element; // Le pointeur pointe sur le dernier élément.
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsm_pile_pop (m_pile **p)
|
||||||
|
{
|
||||||
|
int Val;
|
||||||
|
m_pile *tmp;
|
||||||
|
if (!*p) return -1; // Retourne -1 si la pile est vide.
|
||||||
|
tmp = (*p)->prev;
|
||||||
|
Val = (*p)->value;
|
||||||
|
free (*p);
|
||||||
|
*p = tmp; // Le pointeur pointe sur le dernier élément.
|
||||||
|
return Val; // Retourne la value soutirée de la pile.
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsm_pile_length (m_pile *p)
|
||||||
|
{
|
||||||
|
int n=0;
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
p = p->prev;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsm_pile_view (m_pile *p)
|
||||||
|
{
|
||||||
|
printf ("fsm view pile (n = %d)\n", fsm_pile_length (p));
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
printf ("fsm > %d\n", p->value);
|
||||||
|
p = p->prev;
|
||||||
|
}
|
||||||
|
puts ("------");
|
||||||
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../../include/fsm.h"
|
#include "../../../include/fsm.h"
|
||||||
#include "../../include/util.h"
|
#include "../../../include/util.h"
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
|
@ -100,17 +100,4 @@
|
||||||
|
|
||||||
void fsm_add_measure (char *measure_name) {fsm_debug_msg (2, 0, measure_name, 2);}
|
void fsm_add_measure (char *measure_name) {fsm_debug_msg (2, 0, measure_name, 2);}
|
||||||
|
|
||||||
void fsm_measures_list_init ()
|
|
||||||
{
|
|
||||||
fsm_debug_msg (0,0, "fsm_measures_list_init()", 2); // sub_automaton 2
|
|
||||||
if (0) util_pile_test();
|
|
||||||
if (0) util_double_list_test();
|
|
||||||
if (0) util_sorted_list_test();
|
|
||||||
|
|
||||||
pile *exemple = NULL; // doit être initialisée à NULL
|
|
||||||
printf ("push > %d\n", util_pile_push (&exemple, 4));
|
|
||||||
util_pile_view (exemple);
|
|
||||||
printf ("pop > %d\n", util_pile_pop (&exemple));
|
|
||||||
util_pile_view (exemple);
|
|
||||||
|
|
||||||
}
|
|
|
@ -87,3 +87,4 @@ void util_pile_view (pile *p)
|
||||||
puts ("------");
|
puts ("------");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,12 @@
|
||||||
|
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
|
|
||||||
|
void util_trigger_test ()
|
||||||
|
{
|
||||||
|
if (0) util_pile_test();
|
||||||
|
if (0) util_double_list_test();
|
||||||
|
if (0) util_sorted_list_test();
|
||||||
|
}
|
||||||
|
|
||||||
void util_pile_test()
|
void util_pile_test()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue