BIP Enumerator Header.
More...
Go to the source code of this file.
- Author
- Thorsten Koch
- Date
- 20Nov2014
Definition in file bip_enum.h.
int bip_enumerate |
( |
const BIP * |
bip, |
|
|
bool |
with_output |
|
) |
| |
Prints all solutions.
- Returns
- number of feasible solutions found.
Definition at line 439 of file bip_enum.c.
443 clock_t start = clock();
449 for(
unsigned long long bitvec = 0; bitvec < (1uL << bip->
cols); bitvec++)
451 unsigned long long mask = 1;
458 for(
int j = 0; j < bip->
cols; j++, mask <<= 1)
459 x[j] = (bitvec & mask) ? 1.0 : 0.0;
470 assert((
unsigned)count == (1u << bip->
cols));
472 double elapsed =
GET_SEC(start, clock());
474 printf(
"Checked %d vectors in %.3f s = %.3f kvecs/s\n",
475 count, elapsed, count / elapsed / 1000.0);
static void print_solu(FILE *fp, int vars, const double *x)
Print solution vector.
static bool bip_is_feasible(const BIP *bip, const double *x)
Check whether a particular vector is a feasible solution to a BIP.
int cols
number of columns (variables)
static bool bip_is_valid(const BIP *bip)
Check whether BIP data structure is consistent.
void bip_free |
( |
BIP * |
bip | ) |
|
Definition at line 133 of file bip_enum.c.
static bool bip_is_valid(const BIP *bip)
Check whether BIP data structure is consistent.
Definition at line 91 of file bip_enum.c.
99 #elif defined(USE_LONGLONG)
105 #elif defined(USE_FLOAT)
111 #elif defined(USE_DOUBLE)
117 #elif defined(USE_LONGDOUBLE)
124 #error "No number type defined"
void bip_print |
( |
const BIP * |
bip, |
|
|
FILE * |
fp |
|
) |
| |
Definition at line 359 of file bip_enum.c.
361 const char* sense[3] = {
"<=",
">=",
"==" };
366 for(
int r = 0; r < bip->
rows; r++)
368 for(
int c = 0; c < bip->
cols; c++)
369 fprintf(fp,
"%Lf ", (
long double)bip->
a[r][c]);
370 fprintf(fp,
"%s %Lf\n", sense[bip->
sense[r]], (
long double)bip->
b[r]);
int cols
number of columns (variables)
Numb a[BIP_MAX_ROWS][BIP_MAX_COLS]
coefficient matrix
int rows
number of rows (constraints)
Numb b[BIP_MAX_ROWS]
right hand side
Sense sense[BIP_MAX_ROWS]
equation sense
static bool bip_is_valid(const BIP *bip)
Check whether BIP data structure is consistent.
BIP* bip_read |
( |
const char * |
filename | ) |
|
Format example:
4 # cols (variables) 3 # rows (constraints) 2 3 5 4 <= 8 3 6 0 8 <= 10 0 0 1 1 <= 1
comments (#) and empty lines are ignored.
- Parameters
-
filename | name of file to read |
- Returns
- ptr to BIP data structure
Definition at line 296 of file bip_enum.c.
298 assert(NULL != filename);
299 assert(0 < strlen(filename));
309 if (NULL == (fp = fopen(filename,
"r")))
311 fprintf(stderr,
"Can't open file %s\n", filename);
315 printf(
"Reading %s\n", filename);
317 while(mode !=
READ_ERROR && NULL != (s = fgets(buf,
sizeof(buf), fp)))
337 fprintf(stderr,
"Error: unexpected EOF\n");
346 printf(
"Read %d rows, %d cols\n", bip->
rows, bip->
cols);
#define MAX_LINE_LEN
Maximum input line length.
int max_rows
maximum number of rows
int cols
number of columns (variables)
void bip_free(BIP *bip)
Deallocate BIP data structure.
static LINE_MODE process_line(LINE_MODE mode, const LFS *lfs, const int lines, BIP *bip)
static bool bip_can_overflow(const BIP *bip)
int rows
number of rows (constraints)
LFS * lfs_split_line(LFS *lfs, const char *line, const char *comment)
static bool bip_is_valid(const BIP *bip)
Check whether BIP data structure is consistent.