Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add callback function for logging #21

Open
wants to merge 32 commits into
base: antares_integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
563accb
start
a-zakir Nov 17, 2023
7847e90
add ptr to the caller
a-zakir Nov 17, 2023
50ce16b
add missing include
a-zakir Nov 17, 2023
3096d65
fix
a-zakir Nov 17, 2023
707472c
add helper function
a-zakir Nov 17, 2023
fc453c6
another helper
a-zakir Nov 17, 2023
0ac6c16
test
a-zakir Nov 17, 2023
fa1093f
works but not good at all
a-zakir Nov 18, 2023
2f22d8c
delete debug file
a-zakir Nov 18, 2023
5987e19
add a unique default callback
a-zakir Nov 18, 2023
322d0a7
Hello BB
a-zakir Nov 18, 2023
9086d11
revert "Hello BB"
a-zakir Nov 18, 2023
0015d76
fix
a-zakir Nov 18, 2023
0a385e6
rename var
a-zakir Nov 21, 2023
61a7bb5
begin calling back BB
a-zakir Nov 21, 2023
118c952
add helper func
a-zakir Nov 21, 2023
bcaf4cc
update this file
a-zakir Nov 21, 2023
9eb2ef1
this one also
a-zakir Nov 21, 2023
40369f9
update log
a-zakir Nov 21, 2023
2da4aba
logs
a-zakir Nov 21, 2023
c213b79
format and log
a-zakir Nov 21, 2023
5768c62
format and log...
a-zakir Nov 21, 2023
7e2ea1a
update
a-zakir Nov 21, 2023
ee8111c
avoid unuseful copy
a-zakir Nov 21, 2023
ec08c07
ok
a-zakir Nov 21, 2023
5ada4f7
updating spx_calculer_erbmoins1_avec_base_reduite.c
a-zakir Nov 22, 2023
6acc4f9
spx_calculer_pi_avec_base_reduite.c
a-zakir Nov 22, 2023
cdbb693
spx_calculer_une_gomory
a-zakir Nov 22, 2023
9270748
spx_choix_variable_a_instancier_exploration_rapide_profondeur
a-zakir Nov 22, 2023
b6e735d
spx_construction_matrice_reduite.c
a-zakir Nov 22, 2023
5daf27a
spx_construire_probleme.c
a-zakir Nov 22, 2023
1505baf
spx_creation_noeuds_en_exploration_rapide.c
a-zakir Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/BRANCH_AND_BOUND/bb_affichages_traces.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ int AverageG; int AverageI; int AverageK; char Tracer;
int cpt; int i; int * pt1 ; char * pt2;
# endif

callback_function call_back = (callback_function)Bb->callback;
// TODO else default
if (!call_back)
{
call_back = SiriusDefaultCallback;
}
void *something_from_the_caller = Bb->something_from_the_caller;

if ( NoeudCourant == Bb->NoeudRacine ) {
Bb->TempsDuDernierAffichage = 0;
Bb->NombreDeProblemesDepuisLeDernierAffichage = 0;
Expand All @@ -59,7 +67,9 @@ if ( Bb->NombreDeProblemesResolus > 0 ) {
if ( Bb->TempsDexecutionMaximum > 0 ) {
if ( TempsEcoule >= Bb->TempsDexecutionMaximum ) {
Bb->ArreterLesCalculs = OUI;
if ( Bb->AffichageDesTraces == OUI ) printf("Stopping calculation because time limit reached.\n");
if (Bb->AffichageDesTraces == OUI)
// is this a WARNING?
call_back(something_from_the_caller, "Stopping calculation because time limit reached.\n", 0, SIRIUS_WARN);
}
}

Expand All @@ -74,17 +84,8 @@ if ( Bb->NombreDeProblemesResolus > 0 ) {

if ( Bb->NombreDAffichages == 0 || Bb->NombreDAffichages >= CYCLE_DAFFICHAGE_LEGENDE ) {
Bb->NombreDAffichages = 0;
printf(" ");
printf("| Nodes |");
printf(" Depth (max) |");
printf(" Active nodes |");
printf(" Sol |");
printf(" Best Sol. |");
printf(" Best bound |");
printf(" Gap %% |");
printf(" Seconds |");
printf(" Cuts: average in use (over) |");
printf("\n");
const char *msg = " | Nodes | Depth (max) | Active nodes | Sol | Best Sol. | Best bound | Gap %% | Seconds | Cuts: average in use (over) |\n";
call_back(something_from_the_caller, msg, 0, SIRIUS_INFO);
}
Bb->NombreDAffichages++;

Expand Down
2 changes: 2 additions & 0 deletions src/BRANCH_AND_BOUND/bb_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ int AverageK;
/* */
void * ProblemePneDuBb;

void *callback;
void *something_from_the_caller;
} BB;

/*******************************************************************************************/
Expand Down
19 changes: 19 additions & 0 deletions src/CALLBACK/sirius_callback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#include "sirius_callback.h"
#include <stdio.h>

int SiriusDefaultCallback(void *something_from_the_caller, const char *sMsg, int nLen, SIRIUS_LOGLEVEL log_level)
{
if (nLen <= 0)
{
return 0;
}
if (log_level == SIRIUS_ERROR)
{
fprintf(stderr, sMsg);
}
else
{
printf("%s", sMsg);
}
}
22 changes: 22 additions & 0 deletions src/CALLBACK/sirius_callback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef __cplusplus
extern "C"
{
#endif
#pragma once

#define SIRIUS_CALLBACK_BUFFER_SIZE 1024
typedef enum SIRIUS_LOGLEVEL
{
SIRIUS_TRACE,
SIRIUS_DEBUG,
SIRIUS_INFO,
SIRIUS_WARN,
SIRIUS_ERROR,
SIRIUS_FATAL
} SIRIUS_LOGLEVEL;
typedef int (*callback_function)(void *something_from_the_caller, const char *sMsg, int nLen, SIRIUS_LOGLEVEL log_level);
int SiriusDefaultCallback(void *something_from_the_caller, const char *sMsg, int nLen, SIRIUS_LOGLEVEL log_level);

#ifdef __cplusplus
}
#endif
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ MESSAGE("CMAKE_SOURCE_DIR : ${CMAKE_SOURCE_DIR}")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
SET( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

INCLUDE_DIRECTORIES(. ALLOCATEUR BRANCH_AND_BOUND POINT_INTERIEUR PRESOLVE SIMPLEXE SIMPLEXE/LU PNE SRS)
INCLUDE_DIRECTORIES(. CALLBACK ALLOCATEUR BRANCH_AND_BOUND POINT_INTERIEUR PRESOLVE SIMPLEXE SIMPLEXE/LU PNE SRS)

FILE(GLOB HEADERS ALLOCATEUR/*.h PRESOLVE/*.h BRANCH_AND_BOUND/*.h POINT_INTERIEUR/*.h SIMPLEXE/*.h SIMPLEXE/LU/*.h ./PNE/*.h ./SRS/*.h)
FILE(GLOB HEADERS ./CALLBACK/*.h ALLOCATEUR/*.h PRESOLVE/*.h BRANCH_AND_BOUND/*.h POINT_INTERIEUR/*.h SIMPLEXE/*.h SIMPLEXE/LU/*.h ./PNE/*.h ./SRS/*.h )

FILE(GLOB ALLOCATEUR_FILES ALLOCATEUR/*.c ALLOCATEUR/*.h)
FILE(GLOB PRESOLVE_FILES PRESOLVE/*.c PRESOLVE/*.h)
Expand All @@ -28,15 +28,16 @@ FILE(GLOB SIMPLEXE_FILES SIMPLEXE/*.c SIMPLEXE/*.h)
FILE(GLOB LU_FILES SIMPLEXE/LU/*.c SIMPLEXE/LU/*.h)
FILE(GLOB PNE_FILES PNE/*.c PNE/*.h)
FILE(GLOB SRS_FILES SRS/*.c SRS/*.h)
FILE(GLOB CALLBACK_FILES CALLBACK/*.h CALLBACK/*.c )

GET_FILENAME_COMPONENT(FULL_PATH_TEST_CPP ${CMAKE_CURRENT_SOURCE_DIR}/PNE/pne_standalone.c ABSOLUTE)
MESSAGE("REMOVING FROM SOURCE ${FULL_PATH_TEST_CPP}")
# MESSAGE("-- PNE_FILES : ${PNE_FILES}")
LIST(REMOVE_ITEM PNE_FILES ${FULL_PATH_TEST_CPP})
# MESSAGE("-- PNE_FILES : ${PNE_FILES}")

ADD_LIBRARY(sirius_solver_static STATIC ${ALLOCATEUR_FILES} ${PRESOLVE_FILES} ${BRANCH_AND_BOUND_FILES} ${POINT_INTERIEUR_FILES} ${SIMPLEXE_FILES} ${LU_FILES} ${PNE_FILES} ${SRS_FILES})
ADD_LIBRARY(sirius_solver SHARED ${ALLOCATEUR_FILES} ${PRESOLVE_FILES} ${BRANCH_AND_BOUND_FILES} ${POINT_INTERIEUR_FILES} ${SIMPLEXE_FILES} ${LU_FILES} ${PNE_FILES} ${SRS_FILES})
ADD_LIBRARY(sirius_solver_static STATIC ${CALLBACK_FILES} ${ALLOCATEUR_FILES} ${PRESOLVE_FILES} ${BRANCH_AND_BOUND_FILES} ${POINT_INTERIEUR_FILES} ${SIMPLEXE_FILES} ${LU_FILES} ${PNE_FILES} ${SRS_FILES} )
ADD_LIBRARY(sirius_solver SHARED ${CALLBACK_FILES} ${ALLOCATEUR_FILES} ${PRESOLVE_FILES} ${BRANCH_AND_BOUND_FILES} ${POINT_INTERIEUR_FILES} ${SIMPLEXE_FILES} ${LU_FILES} ${PNE_FILES} ${SRS_FILES} )
#ADD_EXECUTABLE(PNE_STANDALONE PNE/pne_standalone.c )
#ADD_EXECUTABLE(NEWSPX_STANDALONE SPX_STANDALONE/spx_standalone.c )
#ADD_EXECUTABLE(TEST_API TEST_API/main.c )
Expand All @@ -58,6 +59,7 @@ SET_TARGET_PROPERTIES(sirius_solver PROPERTIES PUBLIC_HEADER "${HEADERS}")
SET_TARGET_PROPERTIES(sirius_solver_static PROPERTIES C_STANDARD 11)
SET_TARGET_PROPERTIES(sirius_solver PROPERTIES C_STANDARD 11)
target_include_directories(sirius_solver PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/CALLBACK/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/SRS/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/LU/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/PNE/>)
Expand Down
3 changes: 3 additions & 0 deletions src/PNE/mps_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ int * FirstNomVar;
int * NomVarSuivant;

double objective_offset;
void *callback;
void *something_from_the_caller;

} PROBLEME_MPS;
26 changes: 26 additions & 0 deletions src/PNE/pne_callback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "pne_fonctions.h"
#include "mps_define.h"

int PNEsetcbmessage(PROBLEME_PNE *problem_pne, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level)
{
problem_pne->callback = the_callback_function;
problem_pne->something_from_the_caller = something_from_the_caller;
// TODO
return 0;
}

/*int PROBLEME_MPSsetcbmessage(PROBLEME_MPS *problem_mps, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level)
{
problem_mps->callback = the_callback_function;
problem_mps->something_from_the_caller = something_from_the_caller;
// TODO
return 0;
}*/

int PROBLEME_A_RESOUDREsetcbmessage(PROBLEME_A_RESOUDRE *probleme_a_resoudre, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level)
{
probleme_a_resoudre->callback = the_callback_function;
probleme_a_resoudre->something_from_the_caller = something_from_the_caller;
// TODO
return 0;
}
4 changes: 4 additions & 0 deletions src/PNE/pne_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ jmp_buf Env;

double Critere;


void *callback;
void *something_from_the_caller;

} PROBLEME_PNE;

/*******************************************************************************************/
Expand Down
21 changes: 12 additions & 9 deletions src/PNE/pne_definition_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct {
La matrice des contrainte est decrite par les 4 vecteurs qui suivent. Elle doit etre decrite par ligne.
-> Les coefficients de la matrice des contraintes doivent etre donnes dans un vecteur double precision.
-> En parallele du vecteur des coefficient, il faut donner l'indice colonne du coefficient.
-> Pour chaque ligne (ou premier membre de la contrainte) il faut donner sont indice début dans le vecteur
-> Pour chaque ligne (ou premier membre de la contrainte) il faut donner sont indice d�but dans le vecteur
double precision qui contient les coefficients de la contraintes, et le nombre de coefficients non nuls.
*/
int * IndicesDebutDeLigne ; /* Pour chaque ligne, indice debut de la ligne dans le
Expand All @@ -104,7 +104,7 @@ La matrice des contrainte est decrite par les 4 vecteurs qui suivent. Elle doit
*/
/* Options */
char AlgorithmeDeResolution; /* Doit valoir SIMPLEXE ou POINT_INTERIEUR */
/* Attention, le choix POINT_INTERIEUR ne peut être utilise que dans le cas
/* Attention, le choix POINT_INTERIEUR ne peut �tre utilise que dans le cas
d'un probleme ne comportant pas de varaibles entieres */
char AffichageDesTraces; /* Peut valoir OUI_PNE ou NON_PNE */
char SortirLesDonneesDuProbleme; /* Peut valoir OUI_PNE ou NON_PNE.
Expand All @@ -115,25 +115,28 @@ La matrice des contrainte est decrite par les 4 vecteurs qui suivent. Elle doit
solution optimale n'a pas ete trouvee. Attention, cette grandeur n'est prise en compte
que si le probleme contient des variables entieres */
/* Mettre 0 si le temps est illimite */
int NombreMaxDeSolutionsEntieres; /* Lorsque le nombre de solutions entieres est egal à la valeur de ce
int NombreMaxDeSolutionsEntieres; /* Lorsque le nombre de solutions entieres est egal � la valeur de ce
parametre, le solveur s'arrete et donne la meilleure solution rencontree.
Remarque: mettre une valeur strictement negative pour que ce parametre n'ai pas
de rôle.
de r�le.
*/
double ToleranceDOptimalite; /* Si l'écart relatif entre le cout de la solution entiere trouvee et le plus petit minorant
est inférieur à ToleranceDOptimalite, le solveur s'arrete et considère que la solution
double ToleranceDOptimalite; /* Si l'�cart relatif entre le cout de la solution entiere trouvee et le plus petit minorant
est inf�rieur � ToleranceDOptimalite, le solveur s'arrete et consid�re que la solution
entiere trouvee est la solution optimale.
Convention: ToleranceDOptimalite doit etre exprimé en %.
Convention: ToleranceDOptimalite doit etre exprim� en %.
Conseil : mettre 0 %.
*/
char CoupesLiftAndProject; /* Utile que s'il y a des variables entieres dans le probleme.
Peut valoir OUI_PNE ou NON_PNE. Lorsque cette option vaut OUI_PNE
le calcul des coupes de type lift and project est activé.
- Choix conseillé: NON_PNE car le calcul de ce type de coupe peut être
le calcul des coupes de type lift and project est activ�.
- Choix conseill�: NON_PNE car le calcul de ce type de coupe peut �tre
couteux.
- Mettre OUI_PNE si le probleme est difficile a resoudre.
*/
double objective_offset;
void *callback;
void *something_from_the_caller;

} PROBLEME_A_RESOUDRE;


Expand Down
9 changes: 8 additions & 1 deletion src/PNE/pne_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
de l'inclure pne_constantes_externes.h dans l'appelant. cependant on
le recommande comme ca l'utilisateur sera tente d'aller voir ce qu'il
y a comme constantes externes ce qui n'est pas plus mal */


#include "sirius_callback.h"
//#include "mps_define.h"
/*--------------------------------------------------------------------------------------------------*/

void PNE_SolveurProblemeReduit( PROBLEME_A_RESOUDRE * , CONTROLS * );
Expand Down Expand Up @@ -454,6 +456,11 @@ void PNE_MiseAJourDesSeuilDeSelectionDesCoupes( PROBLEME_PNE * );
/* En test: pour detecter les contraintes d'egalite sur des entiere infaisables */
void PNE_DetectionContraintesEntieresInfaisable( PROBLEME_PNE * );

int PNEsetcbmessage(PROBLEME_PNE *problem_pne, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level);
//int PROBLEME_MPSsetcbmessage(PROBLEME_MPS *problem_pne, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level);
int PROBLEME_A_RESOUDREsetcbmessage(PROBLEME_A_RESOUDRE *problem_pne, callback_function the_callback_function, void *something_from_the_caller, SIRIUS_LOGLEVEL log_level);


/*******************************************************************************************/
# define FONCTIONS_PNE_DEJA_DEFINIES
# endif
Expand Down
10 changes: 7 additions & 3 deletions src/SIMPLEXE/spx_ajouter_coupes.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ CntVarEcartOuArtif = Spx->CntVarEcartOuArtif;
NombreDeContraintes = Spx->NombreDeContraintes;
NombreDeVariables = Spx->NombreDeVariables;

/* Seules nous interessent les variables natives car pour les autres on sait que ça vaut 1 */
callback_function call_back = SPXgetcbmessage(Spx);
void *something_from_the_caller = Spx->something_from_the_caller;
/* Seules nous interessent les variables natives car pour les autres on sait que �a vaut 1 */
CNbTermesDeCoupes = Spx->CNbTermesDeCoupes;
memset ( (char *) CNbTermesDeCoupes, 0 , Spx->NombreDeVariables * sizeof( int ) );

Expand Down Expand Up @@ -212,8 +214,10 @@ for ( Cnt_E = 0 ; Cnt_E < NbContr_E ; Cnt_E++ ) {
else if ( PositionDeLaVariableDEcart[Cnt_E] == HORS_BASE_SUR_BORNE_INF ) {
PositionDeLaVariable[NombreDeVariables] = HORS_BASE_SUR_BORNE_INF;
}
else {
printf("Bug dans le sous programme SPX_AjouterLesCoupes. Arret d'urgence\n");
else
{
const char *msg = "Bug dans le sous programme SPX_AjouterLesCoupes. Arret d'urgence\n";
call_back(something_from_the_caller, msg, 0, SIRIUS_FATAL);
exit(0);
}
/* On la met dans l'equation de la contrainte */
Expand Down
Loading
Loading