@@ -10,15 +10,27 @@ Copyright (C) 2024, Haenn Quentin.
1010#include  <stdio.h> 
1111#include  <stdlib.h> 
1212#include  <string.h> 
13- #include  <signal.h> 
1413#include  <time.h> 
15- #include  <sys/times.h> 
16- #include  <sys/types.h> 
17- #include  <limits.h> 
18- #include  <unistd.h> 
19- #include  <sys/resource.h> 
20- #include  <math.h> 
2114#include  <assert.h> 
15+ #include  <math.h> 
16+ 
17+ #ifdef  _WIN32 
18+     #include  <windows.h> 
19+     #include  <process.h> 
20+     #include  <direct.h> 
21+     #define  SIGINT  2
22+     typedef  void  (* SignalHandlerFn )(int );
23+ #elif  defined(__APPLE__ ) ||  defined(__linux__ )
24+     #include  <sys/time.h> 
25+     #include  <sys/resource.h> 
26+     #include  <sys/types.h> 
27+     #include  <unistd.h> 
28+     #include  <signal.h> 
29+ #else 
30+     #error  "Unsupported platform"
31+ #endif 
32+ 
33+ 
2234#include  "mds3-util.h" 
2335#include  "util_heap.h" 
2436
@@ -1462,7 +1474,7 @@ void check_consistance(){
14621474    assert (!domed (CFG [i ]));
14631475  }
14641476  int  level = -1 ;
1465-   for (int  idx = 0 ;idx < USED (BRA_STK );idx ++ ){
1477+   for (size_t  idx = 0 ;idx < USED (BRA_STK );idx ++ ){
14661478    if (ITEM (BRA_STK ,idx )== NONE ){
14671479      level ++ ;
14681480    }else  if (idx <=BRAIDX [level ])
@@ -1487,7 +1499,7 @@ void check_consistance(){
14871499
14881500
14891501void  cleanup (){
1490-    
1502+ 
14911503  // Free all allocated memory 
14921504  if  (CFG  !=  NULL ) {
14931505    free (CFG );
@@ -1554,15 +1566,35 @@ void cleanup(){
15541566  instance [0 ] =  '\0' ;
15551567}
15561568
1569+ 
15571570void  handler (int  sig ) {
15581571  cleanup ();
15591572  exit (sig );
15601573}
15611574
1562- struct  Result *  emos_main (int *  edges , int  n , int  nb_edge ) {
1575+ #ifdef  _WIN32 
1576+ static  BOOL  WINAPI  win32_handler (DWORD  signal ) {
1577+     if  (signal  ==  CTRL_C_EVENT ) {
1578+         handler (SIGINT );
1579+         return  TRUE;
1580+     }
1581+     return  FALSE;
1582+ }
1583+ 
1584+ static  void  setup_signal_handler (SignalHandlerFn  handler_fn ) {
1585+     SetConsoleCtrlHandler (win32_handler , TRUE);
1586+ }
1587+ #else 
1588+ static  void  setup_signal_handler (void  (* handler_fn )(int )) {
1589+     signal (SIGINT , handler_fn );
1590+ }
1591+ #endif 
1592+ 
1593+ 
1594+ struct  Result *  emos_main (unsigned int  *  edges , int  n , int  nb_edge ) {
15631595
15641596    // Set the signal handler 
1565-   signal ( SIGINT ,  handler );
1597+   setup_signal_handler ( handler );
15661598
15671599  _read_graph_from_edge_list (edges , n , nb_edge );
15681600  NB_NODE_O  =  NB_NODE ;
@@ -1584,7 +1616,7 @@ struct Result* emos_main(int* edges, int n, int nb_edge) {
15841616
15851617  // Get the results 
15861618  int *  dominating_set  =  (int * )malloc (USED (VEC_SOLUTION ) *  sizeof (int ));
1587-   for  (int  i =  0 ; i < USED (VEC_SOLUTION ); i ++ ) {
1619+   for  (size_t  i =  0 ; i < USED (VEC_SOLUTION ); i ++ ) {
15881620    dominating_set [i ] =  ITEM (VEC_SOLUTION , i );
15891621  }
15901622
@@ -1615,22 +1647,4 @@ void free_results(struct Result* result) {
16151647        free (result );
16161648    }
16171649}
1618- 
1619- /** int main(int argc, char *argv[]) { 
1620- 
1621-   print_compile_options(); 
1622-   parse_parmerters(argc,argv); 
1623-   if(read_instance(argv[1])) { 
1624-     initialize(); 
1625-     #ifndef NOR 
1626-     reduce_graph(); 
1627-     #endif 
1628-     partition_oneproblem();     
1629-     solve_subproblems(); 
1630-     check_final_solution(); 
1631-     print_final_solution(getInstanceName(argv[1])); 
1632-     printf("### %s pruning rate %0.2lf total %llu pruned %llu\n",getInstanceName(argv[1]), (total_branches-pruned_branches)/((double)total_branches),total_branches,total_branches-pruned_branches); 
1633-   }	    
1634-   return 0; 
1635- } */ 
16361650
0 commit comments