195 lines
7.1 KiB
C
195 lines
7.1 KiB
C
//=-------------------------------------------------------------------------=//
|
|
// Model definitions //
|
|
// //
|
|
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
|
|
// Copyright © 2021 Adrien Bourmault (neox@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 <https://www.gnu.org/licenses/>. //
|
|
//=-------------------------------------------------------------------------=//
|
|
|
|
#pragma once
|
|
#ifndef BASE_H
|
|
#include "../include/base.h"
|
|
#endif
|
|
|
|
#include <dirent.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <libxml/parser.h>
|
|
#include <libxml/xmlschemas.h>
|
|
|
|
#include "../include/arrows.h"
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#define MODEL_STRING_SIZE 64
|
|
#define MAX_MODEL_NUMBER 1
|
|
|
|
#define ARROW_NUMBER 6
|
|
#define SITE_NUMBER 2
|
|
#define MAX_CYCLES 10
|
|
#define MAX_THREAD 0
|
|
#define XMAX 39
|
|
#define YMAX 0
|
|
#define ZMAX 0
|
|
#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1)
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
struct space_unit_t
|
|
{
|
|
bool lock;
|
|
struct arrow_t **sites; // Array of struct arrow_t* elements
|
|
// - lenght is multiplicity
|
|
};
|
|
|
|
struct space_t
|
|
{
|
|
// Dimensions of space.
|
|
// Note that a value 0 is not allowed, minimum is 1
|
|
int x_dim;
|
|
int y_dim;
|
|
int z_dim;
|
|
|
|
struct space_unit_t *units; // (flat) arraw of space_unit_t elements :
|
|
// - lenght is x_dim * y_dim * z_dim
|
|
// - access to the (x,y,z) is done by
|
|
// units[ x
|
|
// + dim_x * y
|
|
// + dim_x * dim_y * z ]
|
|
};
|
|
|
|
struct state_t
|
|
{
|
|
// Metadata
|
|
char id[25];
|
|
int owner_id;
|
|
time_t date;
|
|
|
|
struct space_t *space;
|
|
};
|
|
|
|
struct model_t
|
|
{
|
|
// Metadata
|
|
char id;
|
|
int owner_id;
|
|
time_t date;
|
|
union version
|
|
{
|
|
int major;
|
|
int minor;
|
|
};
|
|
|
|
// XML handlers
|
|
xmlDocPtr doc;
|
|
xmlHashTablePtr hashtable;
|
|
|
|
// User friendly metadata
|
|
char *owner_name;
|
|
char *model_name;
|
|
char *filename;
|
|
|
|
// Model parameters
|
|
int multiplicity; // number of sites in a space_unit
|
|
int dimension; // number of space dimensions
|
|
|
|
// Simulation parameters
|
|
int max_thread;
|
|
int max_cycles;
|
|
|
|
// Handler to the current space of the model
|
|
struct space_t *space;
|
|
|
|
// Handler to the arrows
|
|
struct arrow_t *arrows;
|
|
size_t n_arrows;
|
|
|
|
// Handler to the saved states array
|
|
struct state_t *states;
|
|
size_t n_states;
|
|
};
|
|
|
|
|
|
struct model_array_t
|
|
{
|
|
struct model_t *models;
|
|
size_t size;
|
|
};
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Model init function (and model discovery) //
|
|
// -------------------------------------------------------------------------- //
|
|
void model_system_init (struct parameters_t *parameters);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Model stopping function //
|
|
// -------------------------------------------------------------------------- //
|
|
// void model_system_shutdown (void);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Load a model ready to execute //
|
|
// -------------------------------------------------------------------------- //
|
|
bool model_load (struct model_t *self);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Unload a model //
|
|
// -------------------------------------------------------------------------- //
|
|
// int model_unload (int id);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Add a model to the known model list //
|
|
// -------------------------------------------------------------------------- //
|
|
// void model_add_to_known (model_t **newModel);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Print informations about all models (known and loaded) to the client //
|
|
// -------------------------------------------------------------------------- //
|
|
// void print_models (char *buf);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Launch a model execution //
|
|
// -------------------------------------------------------------------------- //
|
|
// int model_run (int id);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Stop a model execution //
|
|
// -------------------------------------------------------------------------- //
|
|
// int model_stop (int id);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Stop and unload all loaded or running model //
|
|
// -------------------------------------------------------------------------- //
|
|
// void model_shutdown (void);
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// Parsing primitives //
|
|
// -------------------------------------------------------------------------- //
|
|
|
|
char model_get_dim(struct model_t *self);
|
|
|
|
long model_get_dim_value(struct model_t *self, const char *axis);
|
|
|
|
char model_get_multiplicity(struct model_t *self);
|
|
|
|
bool model_get_next_state(struct model_t *self, char *new_state_id);
|
|
|
|
bool model_get_next_arrow(struct model_t *self,
|
|
struct arrow_t *new_arrow,
|
|
const char *state_id,
|
|
char dimension);
|