-
Notifications
You must be signed in to change notification settings - Fork 2
/
ziround.h
831 lines (734 loc) · 29.7 KB
/
ziround.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
/**
* @file ziround.h
* @author Ivan Viviani
* @copyright Copyright (c) 2020
*/
#pragma once
#ifndef ZIROUND_H_
#define ZIROUND_H_
#include <cplex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <assert.h>
#include <time.h>
#include <windows.h>
#include <winnt.h>
#include "dirent.h"
/**
* @brief Verbosity level.
*/
#define VERBOSE 1
/**
* @brief Plot solution fractionality flag (0-1).
*/
#define PLOT_SOL_FRAC 0
/**
* @brief Plot solution cost flag (0-1).
*/
#define PLOT_SOL_COST 0
/**
* @brief Plot number of rounded variables flag (0-1).
*/
#define PLOT_NUM_VARS_TO_ROUND 0
/**
* @brief Tolerance for non-integer numbers as considered by CPLEX.
*/
#define TOLERANCE 1e-6
/**
* @brief Threshold used in the ZI-Round heuristic.
*/
#define EPSILON 1e-5
/**
* @brief Structure holding local and global information about a
* problem instance, parameters included.
*/
typedef struct {
// Variables
int nrows; /**< Number of rows of the coefficients matrix. */
int ncols; /**< Number of variables, also columns of the coefficients matrix. */
double* x; /**< Current problem solution. Will be rounded. */
double* obj; /**< Objective function coefficients. */
double* lb; /**< Variable lower bounds. */
double* ub; /**< Variable upper bounds. */
double* slack; /**< Row (constraint) slacks, defined as right hand side minus row activity. */
double objval; /**< Current objective value (for current problem solution). */
int objsen; /**< Objective function sense, CPX_MIN (default) or CPX_MAX (specified from command line). */
char* vartype; /**< Variable types (before converting MIP to LP), integer/binary or continuous. */
int* int_var; /**< Flags array that keeps track of integer/binary (value 1) and continuous (value 0) variables. */
int num_int_vars; /**< Number of integer/binary variables to round. */
double solfrac; /**< Solution fractionality. */
// Singletons
int* row_singletons; /**< Singleton indices. */
int rs_size; /**< Total number of singletons. */
int* rs_beg; /**< Begin index of the singleton indices of each row that contains at least one. */
double* rs_coef; /**< Coefficients of the singletons. */
int* num_singletons; /**< Number of singletons for each row. */
double* ss_val; /**< Singleton slack values for each row. */
double* ss_ub; /**< Upper bounds of the singletons slack for each row. */
double* ss_lb; /**< Lower bounds of the singletons slack for each row. */
// Constraints
int nzcnt; /**< Number of non-zero coefficients. */
int* rmatbeg; /**< Begin row indices of non-zero coefficients for rmatind and rmatval. */
int* rmatind; /**< Column indices of non-zero coefficients. */
double* rmatval; /**< Non-zero coefficients (row major). */
int* cmatbeg; /**< Begin column indices of non-zero coefficients for cmatind and cmatval. */
int* cmatind; /**< Row indices of non-zero coefficients. */
double* cmatval; /**< Non-zero coefficients (column major). */
char* sense; /**< Constraint (row) senses, 'L' (<=) or 'G' (>=) or 'E' (=). */
double* rhs; /**< Constraint right hand sides (rhs). */
// Plotting variables
int size_frac; /**< Actual current size of the solution fractionality tracker array. */
int size_cost; /**< Actual current size of the solution cost tracker array. */
int size_toround; /**< Actual current size of the number of variables to round array. */
int len_frac; /**< Maximum length of the solution fractionality tracker array (resizable). */
int len_cost; /**< Maximum length of the solution cost tracker array (resizable). */
int len_toround; /**< Maximum length of the number of rounded variables array (resizable). */
double* tracker_sol_frac; /**< Tracker of solution fractionality. */
double* tracker_sol_cost; /**< Tracker of solution cost. */
double* tracker_toround; /**< Tracker of number of variables to round. */
// Parameters
CPXENVptr env; /**< CPLEX environment pointer. */
CPXLPptr lp; /**< CPLEX lp pointer. */
char input_file[100]; /**< Input filename (mps format, specified from command line). */
char input_folder[100]; /**< Input folder. */
int singletons; /**< Flag for the use of singletons in ZI-Round (default 1 = ON). */
int shift_nonfracvars; /**< Flag for shifting also non-fractional integer variables in ZI-Round (default 1 = ON). */
int sort_singletons; /**< Flag for sorting the singletons of each row in ascending order of objective coefficients (default 0 = OFF). */
int after0frac; /**< Flag for activating the shifting of non-fractional integer varables only when fractionality reaches zero (default 0 = OFF). */
int max_rounds; /**< Flag for controlling the maximum number of rounds (scans of the variables) performed by ZI-Round (default 0 = OFF). */
int fractie_worstobj; /**< Flag for activating the shifting of non-fractional integer variables to worsen the objective when there are ties on the fractionality improvement (default 0 = OFF). */
int timelimit; /**< Time limit in seconds. */
int rseed; /**< Random seed. */
} INSTANCE;
// MAIN.C ----------------------------------------------------------------------------------------------
/**
* @brief Test ZI-Round on a single instance.
*
* @param inst Pointer to the instance.
*/
void test_instance(INSTANCE* inst);
/**
* @brief Test ZI-Round on a folder of instances.
*
* @param inst Pointer to the instance.
* @param test_type The variant of ZI-Round being tested.
*/
void test_folder(INSTANCE* inst, const char* test_type);
/**
* @brief Plot the trackers implemented according to the PLOT_* macros.
*
* @param inst Pointer to the instance.
*/
void plot(INSTANCE* inst);
// -----------------------------------------------------------------------------------------------------
// INSTANCE.C ------------------------------------------------------------------------------------------
/**
* @brief Initialize the appropriate fields of the instance.
*
* @param inst Pointer to the instance.
*/
void init_inst(INSTANCE* inst);
/**
* @brief Deallocate all the fields of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void free_inst(INSTANCE* inst);
// -----------------------------------------------------------------------------------------------------
// CMD_INTERFACE.C -------------------------------------------------------------------------------------
/**
* @brief Parse the arguments from the command line and populate the
* appropriate fields of the already initialized instance.
*
* @param argc Number of command line arguments (includes the program name).
* @param argv Program arguments (strings).
* @param inst Pointer to the instance.
* @param test_type The variant of ZI-Round being tested (user-specified).
*/
void parse_cmd(int argc, char** argv, INSTANCE* inst, char* test_type);
// -----------------------------------------------------------------------------------------------------
// COMPUTE_ZIROUND_INPUT.C -----------------------------------------------------------------------------
/**
* @brief Setup the CPLEX environment for the problem represented by the instance.
* Also turn on CPLEX screen output.
*
* @param inst Pointer to the already initialized and populated instance.
*/
void setup_CPLEX_env(INSTANCE* inst);
/**
* @brief Create the lp into the CPLEX env of the instance and populate the lp
* with problem data read from a file (mps format).
*
* @param inst Pointer to the already populated instance.
* @param filename Name of the input file (mps format).
*/
void read_MIP_problem(INSTANCE* inst, char* filename);
/**
* @brief Read and save variable types from the MIP and save the integer/binary ones in a
* flags array. Both arrays are fields of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void save_integer_variables(INSTANCE* inst);
/**
* @brief Change the problem type from MIP to LP and solve its continuous relaxation.
*
* @param inst Pointer to the already populated instance.
*/
void solve_continuous_relaxation(INSTANCE* inst);
// -----------------------------------------------------------------------------------------------------
// READ_ZIROUND_INPUT.C --------------------------------------------------------------------------------
/**
* @brief Read the problem data from the CPLEX lp using all the read functions,
* and populate the corresponding fields of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void populate_inst(INSTANCE* inst);
/**
* @brief Read the continuous relaxation solution from the CPLEX lp
* and populate the corresponding array field of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_solution(INSTANCE* inst);
/**
* @brief Read the variable bounds from the CPLEX lp
* and populate the corresponding array fields of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_variable_bounds(INSTANCE* inst);
/**
* @brief Read the objective value from the CPLEX lp
* and populate the corresponding field of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_objective_value(INSTANCE* inst);
/**
* @brief Read the objective function coefficients from the CPLEX lp
* and populate the corresponding array field of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_objective_coefficients(INSTANCE* inst);
/**
* @brief Read the non-zero constraint coefficients both by row and column
* from the CPLEX lp, according to the data structures used by CPLEX,
* and populate the corresponding array fields of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_constraints_coefficients(INSTANCE* inst);
/**
* @brief Read the constraint senses from the CPLEX lp,
* and populate the corresponding array field of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_constraints_senses(INSTANCE* inst);
/**
* @brief Read the constraint right hand sides from the CPLEX lp,
* and populate the corresponding array field of the instance.
*
* @param inst Pointer to the already populated instance.
*/
void read_constraints_right_hand_sides(INSTANCE* inst);
/**
* @brief Read the constraint (row) slacks for the continuous relaxation
* solution from the CPLEX lp, and populate the corresponding
* array field of the instance. They will then be updated during
* the rounding phase of zi_round.
*
* @param inst Pointer to the already populated instance.
*/
void read_row_slacks(INSTANCE* inst);
/**
* @brief Find singletons of the problem, i.e. continuous variables that
* appear in only one constraint, and populate the corresponding data structures.
*
* @param inst Pointer to the instance.
*/
void find_singletons(INSTANCE* inst);
/**
* @brief Compute values and bounds of the singletons slacks, seen as a single variable
* (sum of each singleton contribution in the row).
*
* @param inst Pointer to the instance.
*/
void compute_singletons_slacks(INSTANCE* inst);
/**
* @brief Sort singleton indices and coefficients of a single row by lowest objective function coefficient.
*
* @details The row is represented by a \p start and \p end index of the arrays \p rs_ind and \p rs_coef.
*
* @param start Start index of the singleton indices and coefficients of the row.
* @param end End index of the singleton indices and coefficients of the row.
* @param rs_ind Singleton indices.
* @param rs_coef Singleton coefficients.
* @param obj Objective function coefficients.
*/
void sort_singletons(int start, int end, int* rs_ind, double* rs_coef, double* obj);
// -----------------------------------------------------------------------------------------------------
// ZIROUND.C -------------------------------------------------------------------------------------------
/**
* @brief Use the ZI-Round heuristic to round the continuous relaxation solution
* until an integer feasible solution is found or the procedure terminates
* unsuccessfully.
*
* @param inst Pointer to the already populated instance.
* @param numrounds Number of rounds (outer loops) of ZI-Round.
*/
void zi_round(INSTANCE* inst, int* numrounds);
/**
* @brief Check whether all constraints affected by a round up/down of xj have enough slack for it.
*
* @param inst Pointer to the instance.
* @param j Variable index.
* @param delta_up Delta up of variable \p j.
* @param delta_down Delta down of variable \p j.
* @param round_updown
*/
void check_slacks(INSTANCE* inst, int j, double delta_up, double delta_down, const char round_updown);
/**
* @brief Update variable \p j to improve objective, according to the values
* of \p delta_up and \p delta_down calculated before. Also update the row slacks.
*
* @param inst Pointer to the already populated instance.
* @param j Column (variable xj) index.
* @param objcoef Objective coefficient of variable \p j.
* @param delta_up Candidate up-shift of variable \p j.
* @param delta_down Candidate down-shift of variable \p j.
* @param is_fractional Flag that indicates whether variable \p j is fractional or integer.
* @param solfrac Pointer to the solution fractionality.
* @param num_toround Pointer to the number of variables to round.
* @return 1 if variable \p j has been updated, 0 otherwise.
*/
int round_xj_bestobj(INSTANCE* inst, int j, double objcoef, double delta_up, double delta_down, int xj_fractional, double* solfrac, int* num_toround);
/**
* @brief Update variable \p j to worsen objective, according to the values
* of \p delta_up and \p delta_down calculated before. Also update the row slacks.
*
* @param inst Pointer to the already populated instance.
* @param j Column (variable xj) index.
* @param objcoef Objective coefficient of variable \p j.
* @param delta_up Candidate up-shift of variable \p j.
* @param delta_down Candidate down-shift of variable \p j.
* @param xj_fractional Flag that indicates whether variable \p j is fractional or integer.
* @param solfrac Pointer to the solution fractionality.
* @param num_toround Pointer to the number of variables to round.
* @return 1 if variable \p j has been updated, 0 otherwise.
*/
int round_xj_worstobj(INSTANCE* inst, int j, double objcoef, double delta_up, double delta_down, int xj_fractional, double* solfrac, int* num_toround);
/**
* @brief Update the slack array field of the instance (incrementally)
* after a rounding of the current solution (x) field of the instance.
*
* @details Whenever it is called, only one variable xj has been updated.
*
* @param inst Pointer to the already populated instance.
* @param j Index of the (only) variable just updated.
* @param signed_delta Signed delta xj.
*/
void update_slacks(INSTANCE* inst, int j, double signed_delta);
/**
* @brief Update singletons of the constraint \p rowind by distributing \p delta_ss.
*
* @param inst Pointer to the instance.
* @param rowind Index of the constraint.
* @param delta_ss Delta singletons slack to distribute among the singletons of the constraint.
*/
void update_singletons(INSTANCE* inst, int rowind, double delta_ss);
/**
* @brief Compute the j-th entries of the arrays of possible up-shifts and down-shifts
* according to the ZI-Round heuristic specifications.
*
* @param inst Pointer to the already populated instance.
* @param j Variable index.
* @param delta_up Array of possible up-shifts.
* @param delta_down Array of possible down-shifts.
* @param epsilon Tolerance for the computed up/down shifts.
*/
void delta_updown(INSTANCE* inst, int j, double* delta_up, double* delta_down, const double epsilon);
/**
* @brief Compute singletons slack of a given constraint (row).
*
* @param inst Pointer to the instance.
* @param rowind Index of the constraint.
* @return Singletons slack of the constraint.
*/
double compute_ss_val(INSTANCE* inst, int rowind);
// -----------------------------------------------------------------------------------------------------
// UTIL.C ----------------------------------------------------------------------------------------------
/**
* @brief Check that all the variable bounds are satisfied, for the given solution \p x.
*
* @param x Solution to be used for evaluating bounds satisfiability.
* @param lb Lower bounds of the variables.
* @param ub Upper bounds of the variables.
* @param ncols Number of variables.
*/
void check_bounds(double* x, double* lb, double* ub, int ncols);
/**
* @brief Check whether all the constraints are satisfied, for the given solution \p x.
*
* @param x Solution to be used for evaluating constraints satisfiability.
* @param ncols Number of variables.
* @param nrows Number of constraints.
* @param nzcnt Number of non-zero coefficients in the constraints.
* @param rmatbeg Constraints begin indices structure.
* @param rmatind Constraints column indices structure.
* @param rmatval Constraint coefficients.
* @param sense Constraint senses.
* @param rhs Constraint right hand sides.
*/
void check_constraints(double* x, int ncols, int nrows, int nzcnt, int* rmatbeg, int* rmatind, double* rmatval, char* sense, double* rhs);
/**
* @brief Check whether all the integer variables of the original MIP have been rounded.
*
* @param x Current solution.
* @param ncols Number of variables.
* @param int_var Array of flags for binary/integer variables in the original MIP.
* @param vartype Array of variable types.
* @return 1 iff all integer/binary variables have been rounded, 0 otherwise.
*/
int check_rounding(double* x, int ncols, int* int_var, char* vartype);
/**
* @brief Count number of variables rounded so far.
*
* @param x Current solution.
* @param ncols Number of variables.
* @param int_var Array of flags for binary/integer variables in the original MIP.
* @param vartype Array of variable types.
* @return Number of variables rounded so far.
*/
int count_rounded(double* x, int ncols, int* int_var, char* vartype);
/**
* @brief Calculate the fractionality of the given value.
*
* @param xj Value.
* @return Fractionality of the value.
*/
double fractionality(double xj);
/**
* @brief Calculate the fractionality of a solution.
*
* @param x Solution.
* @param int_var Flags array for integer variables.
* @param len Length of the array.
* @return Fractionality of the solution.
*/
double sol_fractionality(double* x, int* int_var, int len);
/**
* @brief Check the integrality of the given value.
*
* @param num Value.
* @return 1 if the value is fractional, 0 otherwise.
*/
int is_fractional(double num);
/**
* @brief Calculate the dot product of two arrays (of the same length).
*
* @param coef First array.
* @param var_value Second array.
* @param len Length of both arrays.
* @return Dot product of the two arrays.
*/
double dot_product(double* coef, double* var_value, int len);
/**
* @brief Free memory allocated to multiple pointers.
*
* @details It does not check the type of the passed ellipsis parameters, so
* be sure that actual pointers are passed. Use with care.
*
* @param count The number of pointers.
* @param ... The actual pointers.
*/
void free_all(int count, ...);
/**
* @brief Create a text file with the list of instances in a folder (instances must be .mps files).
*
* @param folder_path The path to the folder containing the instances.
* @param output_file The path to the output file containing the list of instances created.
*/
void create_instances_list(const char* folder_path, const char* output_file);
// -----------------------------------------------------------------------------------------------------
// PLOT.C ----------------------------------------------------------------------------------------------
/**
* @brief Given a tracker, add a new point to it.
*
* @param point The point to add to the \p tracker.
* @param tracker The tracking array.
* @param len The actual length of the \p tracker.
* @param size The number of \p point elements currently in the tracker.
*/
void add_point_single_tracker(double point, double** tracker, int* len, int* size);
/**
* @brief Given a multivariate tracker, add a new point to it.
*
* @param point The new point to add to the multivariate tracker, represented by an array.
* @param tracker The tracking matrix.
* @param num The number of dimensions of the multivariate tracker.
* @param len The size of the tracker.
* @param size The number of elements currently in each tracker.
*/
void add_point_multivariate_tracker(double* point, double** tracker, int num, int* len, int* size);
/**
* @brief Plot the results of a single tracker.
*
* @param tracker The array with the tracking information.
* @param name The name of the tracker.
* @param label The labels of x and y axes.
* @param size The size of the array.
* @param filename The name of the file, where the plot is saved, this file
* should have the `.png` extension. If this parameter is `NULL` the plot
* is displayed on the screen.
*/
void plot_tracker(double* tracker, char* name, char** label, int size, char* filename);
/**
* @brief Plot the results of a pair of trackers with two different y-axis.
*
* @param first_tracker The array with the first tracker information.
* @param second_tracker The array with the second tracker information.
* @param name The names of the two trackers.
* @param label The labels of the two trackers (x, y1, y2).
* @param size The size of both arrays.
* @param filename The name of the file, where the plot is saved, this file
* should have the `.png` extension. If this parameter is `NULL` the plot
* is displayed on the screen.
*/
void plot_tracker_pair(double* first_tracker, double* second_tracker, char** name, char** label, int size, char* filename);
/**
* @brief Plot the results of a multivariate tracker on the same plot.
*
* @param tracker The matrix with tracking information.
* @param name The names of the tracker dimensions.
* @param label The labels of x and y axes.
* @param num The number of dimensions of the tracker.
* @param size The size of the tracker.
* @param filename The name of the file, where the plot is saved, this file
* should have the .png extension. If this parameter is null, the plot
* is displayed on the screen.
*/
void plot_multivariate_tracker(double** tracker, char** name, char** label, int num, int size, char* filename);
/**
* @brief Open a pipe, and set basic properties.
*
* @details The pipe is opened and the FILE* of the pipe is inserted in the
* pointer at address \p pointer_to_g_plot_pipe. \p filename is used to
* choose if the plot must be displayed or saved as an image: according to it,
* gnuplot is properly set. Finally a set of `6` styles is defined: `(1,2,...6)`.
*
* @param pointer_to_g_plot_pipe The pointer to the pointer to the file that
* represents the pipe. This indirection is required to modify the
* value of the pointer to the file.
* @param filename The name of the file, with the meaning described in the
* main plot functions.
*/
static void open_pipe(FILE** pointer_to_g_plot_pipe, char* filename);
/**
* @brief Close the pipe, forcing a flush.
*
* @param g_plot_pipe The pipe to close.
*/
static void close_pipe(FILE* g_plot_pipe);
// -----------------------------------------------------------------------------------------------------
// PRINT.C ---------------------------------------------------------------------------------------------
/**
* @brief Print a warning message. The message is preceeded by `"\n\nWARNING: "`.
*
* @param warn The warning message to print, including the format for the ellipsis parameters.
* @param ... The multiple parameters.
*/
void print_warning(const char* warn, ...);
/**
* @brief Print an error message and exit. The message is preceeded by `"\n\nERROR: "`.
*
* @param err The error message to print, including the format for the ellipsis parameters.
* @param ... The multiple parameters.
*/
void print_error(const char* err, ...);
/**
* @brief Print the passed message iff the verbosity level of the message is lower
* than the global parameter `VERBOSE`.
*
* @param msg_verb The level of verbosity of this message.
* @param format The message to print, including the format for the ellipsis parameters.
* @param ... The multiple parameters.
*/
void print_verbose(int msg_verb, const char* format, ...);
// -----------------------------------------------------------------------------------------------------
// ASSERTS.C -------------------------------------------------------------------------------------------
/**
* @brief Check whether an integer number is positive.
*
* @param num Integer number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int positive_integer(int num);
/**
* @brief Check whether an integer number is non-negative.
*
* @param num Integer number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int non_negative_integer(int num);
/**
* @brief Check whether a floating point number is non-negative.
*
* @param num Number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int non_negative(double num);
/**
* @brief Check whether a floating point number is non-positive.
*
* @param num Number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int non_positive(double num);
/**
* @brief Check whether a floating point number is negative.
*
* @param num Number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int negative(double num);
/**
* @brief Check whether a floating point number is positive.
*
* @param num Number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int positive(double num);
/**
* @brief Check whether a floating point number is equal to zero.
*
* @param num Number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int zero(double num);
/**
* @brief Check whether two floating point numbers are equal.
*
* @param x First number.
* @param y Second number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int equals(double x, double y);
/**
* @brief Check whether two floating point numbers are not equal.
*
* @param x First number.
* @param y Second number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int not_equals(double x, double y);
/**
* @brief Check whether for two floating point numbers it holds that the
* first is less than the second.
*
* @param x First number.
* @param y Second number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int less_than(double x, double y);
/**
* @brief Check whether for two floating point numbers it holds that the
* first is greater than the second.
*
* @param x First number.
* @param y Second number.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int greater_than(double x, double y);
/**
* @brief Check whether the numeric code for the objective sense is valid
* according to CPLEX.
*
* @param objsen Objective sense code.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int valid_obj_sense(int objsen);
/**
* @brief Check whether there is a ranged constraint in an array of
* constraint senses.
*
* @param sense Array of constraint senses.
* @param nrows Size of the array.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int no_ranged_constraints(char* sense, int nrows);
/**
* @brief Check whether row slacks are valid, i.e. have the correct sign.
*
* @param slack Array of row slacks.
* @param sense Array of constraint senses.
* @param nrows Size of the two arrays.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int valid_row_slacks(double* slack, char* sense, int nrows);
/**
* @brief Check whether variable types are supported in the program.
*
* @param vartype Array of variable types.
* @param ncols Size of the array.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int valid_var_types(char* vartype, int ncols);
/**
* @brief Check whether a variable type is integer or binary.
*
* @param vartype Variable type.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int var_type_integer_or_binary(char vartype);
/**
* @brief Check whether a variable type is continuous.
*
* @param vartype Variable type.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int var_type_continuous(char vartype);
/**
* @brief Check whether an index is within its bounds
* (it is assumed to have a lower bound of zero).
*
* @param ind Index.
* @param len Upper bound.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int index_in_bounds(int ind, int len);
/**
* @brief Check whether an array of integers is all zeros.
*
* @param arr Array of integers.
* @param len Size of the array.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int array_of_zeros(int* arr, int len);
/**
* @brief Check whether a set of bounds is valid, i.e. lower bounds
* less than upper bounds.
*
* @param lower Array of lower bounds.
* @param upper Array of upper bounds.
* @param nvars Size of the two arrays.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int valid_bounds(double* lower, double* upper, int nvars);
/**
* @brief Check whether a variable is within its bounds.
*
* @param var Variable value.
* @param lb Lower bound.
* @param ub Upper bound.
* @return 1 If the assert succeeds, 0 otherwise.
*/
int var_in_bounds(double var, double lb, double ub);
// -----------------------------------------------------------------------------------------------------
#endif /* ZIROUND_H_ */