int unique(struct regs *regs,char *name,int ncols,int col) { char *bf=find_col(name,col+1); struct regs *r; printf("ncols=%d, del col=%d, postfix=%s\n",ncols,col,bf); for(r=regs;r;r=r->next) if(count_cols(r->name)==ncols && !strcmp(bf,find_col(r->name,col+1))) { char buf1[1024]; struct regs *s; remove_col(buf1,r->name,col); printf("Checking %s (reduced to %s)\n",r->name,buf1); for(s=regs;s;s=s->next) if(!strcmp(buf1,s->name)) return 0; else if(s!=r && count_cols(s->name)==ncols && !strcmp(bf,find_col(s->name,col+1))) { char buf2[1024]; remove_col(buf2,s->name,col); printf("Comparing %s %s\n",buf1,buf2); if(!strcmp(buf1,buf2)) return 0; } } return 1; }
int remove_it(struct regs *r,char *name,int ncols,int col) { char *bf=find_col(name,col+1); while(r) { if(count_cols(r->name)==ncols && !strcmp(bf,find_col(r->name,col+1))) { char bf[1024]; remove_col(bf,r->name,col); printf("removing %s to %s\n",r->name,bf); r->name=strdup(bf); } r=r->next; } }
static void parse_integer(struct dsa *dsa) { int j, binary; /* parse the keyword 'general', 'integer', or 'binary' */ if (dsa->token == T_GENERAL) binary = 0, scan_token(dsa); else if (dsa->token == T_INTEGER) binary = 0, scan_token(dsa); else if (dsa->token == T_BINARY) binary = 1, scan_token(dsa); else xassert(dsa != dsa); /* parse list of variables (may be empty) */ while (dsa->token == T_NAME) { /* find the corresponding column */ j = find_col(dsa, dsa->image); /* change kind of the variable */ #if 0 lpx_set_class(dsa->lp, LPX_MIP); #endif lpx_set_col_kind(dsa->lp, j, LPX_IV); /* set 0-1 bounds for the binary variable */ if (binary) { set_lower_bound(dsa, j, 0.0); set_upper_bound(dsa, j, 1.0); } scan_token(dsa); } return; }
static void parse_integer(struct csa *csa) { int j, binary; /* parse the keyword 'general', 'integer', or 'binary' */ if (csa->token == T_GENERAL) binary = 0, scan_token(csa); else if (csa->token == T_INTEGER) binary = 0, scan_token(csa); else if (csa->token == T_BINARY) binary = 1, scan_token(csa); else xassert(csa != csa); /* parse list of variables (may be empty) */ while (csa->token == T_NAME) { /* find the corresponding column */ j = find_col(csa, csa->image); /* change kind of the variable */ glp_set_col_kind(csa->P, j, GLP_IV); /* set bounds for the binary variable */ if (binary) #if 0 /* 07/VIII-2013 */ { set_lower_bound(csa, j, 0.0); set_upper_bound(csa, j, 1.0); } #else { set_lower_bound(csa, j, csa->lb[j] == +DBL_MAX ? 0.0 : csa->lb[j]); set_upper_bound(csa, j, csa->ub[j] == -DBL_MAX ? 1.0 : csa->ub[j]); } #endif scan_token(csa); } return; }
static int parse_linear_form(struct dsa *dsa) { int j, k, len = 0, newlen; double s, coef; loop: /* parse an optional sign */ if (dsa->token == T_PLUS) s = +1.0, scan_token(dsa); else if (dsa->token == T_MINUS) s = -1.0, scan_token(dsa); else s = +1.0; /* parse an optional coefficient */ if (dsa->token == T_NUMBER) coef = dsa->value, scan_token(dsa); else coef = 1.0; /* parse a variable name */ if (dsa->token != T_NAME) fatal(dsa, "missing variable name"); /* find the corresponding column */ j = find_col(dsa, dsa->image); /* check if the variable is already used in the linear form */ if (dsa->map[j]) fatal(dsa, "multiple use of variable `%s' not allowed", dsa->image); /* mark that the variable is used in the linear form */ dsa->map[j] = 1; /* add new term to the linear form */ len++, dsa->ind[len] = j, dsa->val[len] = s * coef; scan_token(dsa); /* if the next token is a sign, there is another term */ if (dsa->token == T_PLUS || dsa->token == T_MINUS) goto loop; /* clear marks of the variables used in the linear form */ for (k = 1; k <= len; k++) dsa->map[dsa->ind[k]] = 0; /* remove zero coefficients */ newlen = 0; for (k = 1; k <= len; k++) { if (dsa->val[k] != 0.0) { newlen++; dsa->ind[newlen] = dsa->ind[k]; dsa->val[newlen] = dsa->val[k]; } } return newlen; }
int main(int argc, char * argv[]) { line_t line; int i, j, col_index; int first_line = 1; if (argc < 5) showusage(); if (strcmp(argv[1], "-") != 0) line.pin = try_open(argv[1], "rb"); else line.pin = stdin; col_index = atoi(argv[2]); int pouts_len = atoi(argv[3]); const char* output_format = argv[4]; FILE ** pouts = (FILE **) malloc( pouts_len * sizeof(FILE *) ); char out_path[256]; for (i = 0; i != pouts_len; ++i) { sprintf(out_path, output_format, i); pouts[i] = try_open(out_path, "wb"); } while (fgets(line.buf, sizeof(line.buf), line.pin)) { if (first_line) { for (j = 0; j != pouts_len; ++j) { fputs(line.buf, pouts[j]); // write header to all the files first_line = 0; } } else if ( find_col(col_index, &line) ) // if this string has the requisite number of columns fputs(line.buf, pouts[fnv_hash(line.col_beg, line.col_end) % pouts_len]); // write it to the correct file } if (line.pin != stdin) fclose(line.pin); for (i = 0; i != pouts_len; ++i) fclose(pouts[i]); return 0; }
static void parse_bounds(struct dsa *dsa) { int j, lb_flag; double lb, s; /* parse the keyword 'bounds' */ xassert(dsa->token == T_BOUNDS); scan_token(dsa); loop: /* bound definition can start with a sign, numeric constant, or a symbolic name */ if (!(dsa->token == T_PLUS || dsa->token == T_MINUS || dsa->token == T_NUMBER || dsa->token == T_NAME)) goto done; /* parse bound definition */ if (dsa->token == T_PLUS || dsa->token == T_MINUS) { /* parse signed lower bound */ lb_flag = 1; s = (dsa->token == T_PLUS ? +1.0 : -1.0); scan_token(dsa); if (dsa->token == T_NUMBER) lb = s * dsa->value, scan_token(dsa); else if (the_same(dsa->image, "infinity") || the_same(dsa->image, "inf")) { if (s > 0.0) fatal(dsa, "invalid use of `+inf' as lower bound"); lb = -DBL_MAX, scan_token(dsa); } else fatal(dsa, "missing lower bound"); } else if (dsa->token == T_NUMBER) { /* parse unsigned lower bound */ lb_flag = 1; lb = dsa->value, scan_token(dsa); } else { /* lower bound is not specified */ lb_flag = 0; } /* parse the token that should follow the lower bound */ if (lb_flag) { if (dsa->token != T_LE) fatal(dsa, "missing `<', `<=', or `=<' after lower bound"); scan_token(dsa); } /* parse variable name */ if (dsa->token != T_NAME) fatal(dsa, "missing variable name"); j = find_col(dsa, dsa->image); /* set lower bound */ if (lb_flag) set_lower_bound(dsa, j, lb); scan_token(dsa); /* parse the context that follows the variable name */ if (dsa->token == T_LE) { /* parse upper bound */ scan_token(dsa); if (dsa->token == T_PLUS || dsa->token == T_MINUS) { /* parse signed upper bound */ s = (dsa->token == T_PLUS ? +1.0 : -1.0); scan_token(dsa); if (dsa->token == T_NUMBER) { set_upper_bound(dsa, j, s * dsa->value); scan_token(dsa); } else if (the_same(dsa->image, "infinity") || the_same(dsa->image, "inf")) { if (s < 0.0) fatal(dsa, "invalid use of `-inf' as upper bound"); set_upper_bound(dsa, j, +DBL_MAX); scan_token(dsa); } else fatal(dsa, "missing upper bound"); } else if (dsa->token == T_NUMBER) { /* parse unsigned upper bound */ set_upper_bound(dsa, j, dsa->value); scan_token(dsa); } else fatal(dsa, "missing upper bound"); } else if (dsa->token == T_GE) { /* parse lower bound */ if (lb_flag) { /* the context '... <= x >= ...' is invalid */ fatal(dsa, "invalid bound definition"); } scan_token(dsa); if (dsa->token == T_PLUS || dsa->token == T_MINUS) { /* parse signed lower bound */ s = (dsa->token == T_PLUS ? +1.0 : -1.0); scan_token(dsa); if (dsa->token == T_NUMBER) { set_lower_bound(dsa, j, s * dsa->value); scan_token(dsa); } else if (the_same(dsa->image, "infinity") || the_same(dsa->image, "inf") == 0) { if (s > 0.0) fatal(dsa, "invalid use of `+inf' as lower bound"); set_lower_bound(dsa, j, -DBL_MAX); scan_token(dsa); } else fatal(dsa, "missing lower bound"); } else if (dsa->token == T_NUMBER) { /* parse unsigned lower bound */ set_lower_bound(dsa, j, dsa->value); scan_token(dsa); } else fatal(dsa, "missing lower bound"); } else if (dsa->token == T_EQ) { /* parse fixed value */ if (lb_flag) { /* the context '... <= x = ...' is invalid */ fatal(dsa, "invalid bound definition"); } scan_token(dsa); if (dsa->token == T_PLUS || dsa->token == T_MINUS) { /* parse signed fixed value */ s = (dsa->token == T_PLUS ? +1.0 : -1.0); scan_token(dsa); if (dsa->token == T_NUMBER) { set_lower_bound(dsa, j, s * dsa->value); set_upper_bound(dsa, j, s * dsa->value); scan_token(dsa); } else fatal(dsa, "missing fixed value"); } else if (dsa->token == T_NUMBER) { /* parse unsigned fixed value */ set_lower_bound(dsa, j, dsa->value); set_upper_bound(dsa, j, dsa->value); scan_token(dsa); } else fatal(dsa, "missing fixed value"); } else if (the_same(dsa->image, "free")) { /* parse the keyword 'free' */ if (lb_flag) { /* the context '... <= x free ...' is invalid */ fatal(dsa, "invalid bound definition"); } set_lower_bound(dsa, j, -DBL_MAX); set_upper_bound(dsa, j, +DBL_MAX); scan_token(dsa); } else if (!lb_flag) { /* neither lower nor upper bounds are specified */ fatal(dsa, "invalid bound definition"); } goto loop; done: return; }