⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readmps.c

📁 matlab整数规划工具箱
💻 C
📖 第 1 页 / 共 2 页
字号:

	if(Debug) {
	  fprintf(stderr, "Rows line: ");
	  fprintf(stderr, "%s %s\n", field1, field2);
	}
         
	if(strcmp(field1, "N") == 0) {
	  if(!OF_found) { /* take the first N row as OF, ignore others */
	    set_row_name(Mlp, 0, field2); 
	    OF_found = TRUE;
	  }
	  else if(!Unconstrained_rows_found) {
	    fprintf(stderr, "Unconstrained row %s will be ignored\n", field2);
	    fprintf(stderr,
		    "Further messages of this kind will be surpressed\n");
	    Unconstrained_rows_found = TRUE;
	  }
	}
	else if(strcmp(field1, "L") == 0) {
	  str_add_constraint(Mlp, "" ,LE ,0);
	  set_row_name(Mlp, Mlp->rows, field2); 
	}
	else if(strcmp(field1, "G") == 0) {
	  str_add_constraint(Mlp, "" ,GE ,0);
	  set_row_name(Mlp, Mlp->rows, field2); 
	}
	else if(strcmp(field1, "E") == 0) {
	  str_add_constraint(Mlp, "",EQ ,0);
	  set_row_name(Mlp, Mlp->rows, field2); 
	}
	else {
	  fprintf(stderr, "Unknown relat '%s' on line %d\n", field1, Lineno);
	  exit(EXIT_FAILURE);
	}
	break;

      case COLUMNS:
	/* field2: variable; field3: constraint; field4: coef */
	/* optional: field5: constraint; field6: coef */

	if(Debug) {
	  fprintf(stderr, "Columns line: ");
	  fprintf(stderr, "%s %s %g %s %g\n", field2, field3, field4, field5,
		  field6);
	}

	if((items == 4) || (items == 6)) {
	  if (strcmp(field2, Last_col_name) != 0 && Column_ready) { 
	    addmpscolumn();
	    strcpy(Last_col_name, field2);
	    Column_ready = TRUE;
	  }
	  else {
	    strcpy(Last_col_name, field2);
	    Column_ready = TRUE;
	  }
	  if((row = find_row(field3)) >= 0) {
	    Last_column[row] = (REAL)field4;             
	  }
	}
	if(items == 6) {
	  if((row = find_row(field5)) >= 0) {
	    Last_column[row] = (REAL)field6;
	  }
	}

	if(items == 5) { /* there might be an INTEND or INTORG marker */
	  /* look for "    <name>  'MARKER'                 'INTORG'" */
	  /* or "    <name>  'MARKER'                 'INTEND'" */
	  if(strcmp(field3, "'MARKER'") ==0) {
	    addmpscolumn();
	    if(strcmp(field5, "'INTORG'") == 0) {
	      Int_section = TRUE;
	      if(Debug)
		fprintf(stderr, "Switching to integer section\n");
	    }
	    else if(strcmp(field5, "'INTEND'") == 0) {
	      Int_section = FALSE;
	      if(Debug)
		fprintf(stderr, "Switching to non-integer section\n");
	    }
	    else
	      fprintf(stderr, "Unknown marker (ignored) at line %d: %s\n",
		      Lineno, field5);
	  }
	}

	if((items != 4) && (items != 6) && (items != 5)) { /* Wrong! */
	  fprintf(stderr,
		  "Wrong number of items (%d) in COLUMNS section (line %d)\n",
		  items, Lineno);
	  exit(EXIT_FAILURE);
	}
	break;

      case RHS:
	/* field2: uninteresting name; field3: constraint name */
	/* field4: value */
	/* optional: field5: constraint name; field6: value */

	if(Debug) {
	  fprintf(stderr, "RHS line: ");
	  fprintf(stderr, "%s %s %g %s %g\n", field2, field3, field4, field5,
		  field6);
	}

	if((items != 4) && (items != 6)) {
	  fprintf(stderr,
		  "Wrong number of items (%d) in RHS section line %d\n",
		  items, Lineno);
	  exit(EXIT_FAILURE);
	}

	if((row = find_row(field3)) >= 0) {
	  set_rh(Mlp, row, (REAL)field4);
	}

	if(items == 6) {
	  if((row = find_row(field5)) >= 0) {
	    set_rh(Mlp, row, (REAL)field6);
	  }
	}

	break;

      case BOUNDS:
	/* field1: bound type; field2: uninteresting name; */
	/* field3: variable name; field4: value */

	if(Debug) {
	  fprintf(stderr, "BOUNDS line: %s %s %s %g\n", field1, field2, field3,
		  field4);
	}

	var = find_var(field3);
	
	if(strcmp(field1, "UP") == 0) {
	  /* upper bound */
	  set_upbo(Mlp, var, field4);
	}
	else if(strcmp(field1, "LO") == 0) {
	  /* lower bound */
	  set_lowbo(Mlp, var, field4);
	}
	else if(strcmp(field1, "FX") == 0) {
	  /* fixed, upper _and_ lower  */
	  set_lowbo(Mlp, var, field4);
	  set_upbo(Mlp, var, field4);
	}
	else if(strcmp(field1, "PL") == 0)
	  /* normal, 0 <= var <= inf, do nothing */;
	else if(strcmp(field1, "BV") == 0) { /* binary variable */
	  set_upbo(Mlp, var, 1);
	  set_int(Mlp, var, TRUE);
	}
	/* begging of AMPS bounds type UI and LI added by E.Imamura (CRIEPI)  */
	else if(strcmp(field1, "UI") == 0) { /* upper bound for integer variable */
	  set_upbo(Mlp, var, field4);
	  set_int(Mlp, var, TRUE);
	}
	else if(strcmp(field1, "UI") == 0) { /* lower bound for integer variable */
	  set_lowbo(Mlp, var, field4);
	  set_int(Mlp, var, TRUE);
	}
	/* end of  AMPS bounds type UI and LI added by E.Imamura (CRIEPI)  */
	/* hack for free and negative variables. Ugly, and does not
	   always work. MB */
	else if(strcmp(field1, "FR") == 0) { /* free variable */
	  fprintf(stderr, 
		  "Free variable %s is split in a positive part %s and a negative part %s_\n",
		  field3, field3, field3);
	  get_column(Mlp, var, Last_column);
	  for (i = 0; i <= Mlp->rows; i++)
	    Last_column[i]*=-1;
	  add_column(Mlp, Last_column);
	  strcat(field3, "_");
	  set_col_name(Mlp, Mlp->columns, field3);
	  /* should lower and upper bounds of both variables be adjusted? What
	     if lower and upper bound are specified later? MB */
	}
	else if(strcmp(field1, "MI") == 0) { /* negative variable */
	  fprintf(stderr,
		  "Negative variable %s will be represented by - %s-\n",
		  field3, field3);
	  get_column(Mlp, var, Last_column);
	  del_column(Mlp, var);
	  for (i = 0; i <= Mlp->rows; i++)
	    Last_column[i] *= -1;
	  add_column(Mlp, Last_column);
	  strcat(field3, "-");
	  set_row_name(Mlp, var, field3);
	  /* should lower and upper bounds of variable be adjusted? What if
	     lower and upper bound are specified later? (does not work!) MB */
	}
	else {
	  fprintf(stderr, "BOUND type %s on line %d is not supported\n",
		  field1, Lineno);
	  exit(EXIT_FAILURE);
	}
	      
	break;
               
      case RANGES:

	/* We have to implement the following semantics:

	  D. The RANGES section is for constraints of the form: h <=
	  constraint <= u .  The range of the constraint is r = u - h .  The
	  value of r is specified in the RANGES section, and the value of u or
	  h is specified in the RHS section.  If b is the value entered in the
	  RHS section, and r is the value entered in the RANGES section, then
	  u and h are thus defined:

          row type       sign of r       h          u
          ----------------------------------------------
             G            + or -         b        b + |r|
             L            + or -       b - |r|      b
             E              +            b        b + |r|
             E              -          b - |r|      b
	*/

	/* field2: uninteresting name; field3: constraint name */
	/* field4: value */
	/* optional: field5: constraint name; field6: value */

	if(Debug) {
	  fprintf(stderr, "RANGES line: ");
	  fprintf(stderr, "%s %s %g %s %g\n", field2, field3, field4, field5,
		  field6);
	}

	if((items != 4) && (items != 6)) {
	  fprintf(stderr,
		  "Wrong number of items (%d) in RANGES section line %d\n",
		  items, Lineno);
	  exit(EXIT_FAILURE);
	}

	if(((row = find_row(field3)) >= 0) && (field4 != 0)) {
	  /* find out constraint type. If ch_sign[row] is TRUE, it is GE. If
	     ch_sign[row] is FALSE, it is an equality constraint if
	     orig_upbo[row] == 0. For a LE constraint, orig_upbo[row] should be
	     +infinity */
	 
	  if(my_abs(field4) >= Mlp->infinite) {
	    fprintf(stderr,
		    "Warning, Range for row %s >= infinity (value %g) on line %d, ignoring\n",
		    field3, field4, Lineno);
	  }
	  else if(Mlp->ch_sign[row]) {
	    /* GE */
	    Mlp->orig_upbo[row] = my_abs(field4);
	  }
	  else if(Mlp->orig_upbo[row] == 0 && field4 >= 0) {
	    /*  EQ with positive sign of r value */
	    set_constr_type(Mlp, row, GE);
	    Mlp->orig_upbo[row] = field4;
	  }
	  else if(Mlp->orig_upbo[row] == Mlp->infinite) {
	    /* LE */
	    Mlp->orig_upbo[row] = my_abs(field4);
	  }
	  else if(Mlp->orig_upbo[row] == 0 && field4 < 0) {
	    /* EQ with negative sign of r value */
	    set_constr_type(Mlp, row, LE);
	    Mlp->orig_upbo[row] = -field4;
	  }
	  else { /* let's be paranoid */
	    fprintf(stderr,
		    "Cannot figure out row type, row = %d, ch_sign = %d, upbo = %g\n",
		    row, Mlp->ch_sign[row], (double)Mlp->orig_upbo[row]);
	  }
	}

	if(items == 6) {
	  if(((row = find_row(field5)) >= 0) && (field6 != 0)) {
	    /* find out constraint type. If ch_sign[row] is TRUE, it is GE. If
	       ch_sign[row] is FALSE, it is an equality constraint if
	       orig_upbo[row] == 0. For a LE constraint, orig_upbo[row] should
	       be +infinity */
	    
	    if(my_abs(field6) >= Mlp->infinite) {
	      fprintf(stderr,
		      "Warning, Range for row %s >= infinity (value %g) on line %d, ignoring\n",
		      field5, field6, Lineno);
	    }
	    else if(Mlp->ch_sign[row]) {
	      /* GE */
	      Mlp->orig_upbo[row] = my_abs(field6);
	    }
	    else if(Mlp->orig_upbo[row] == 0 && field6 >= 0) {
	      /*  EQ with positive sign of r value */
	      set_constr_type(Mlp, row, GE);
	      Mlp->orig_upbo[row] = field6;
	    }
	    else if(Mlp->orig_upbo[row] == Mlp->infinite) {
	      /* LE */
	      Mlp->orig_upbo[row] = my_abs(field6);
	    }
	    else if(Mlp->orig_upbo[row] == 0 && field6 < 0) {
	      /* EQ with negative sign of r value */
	      set_constr_type(Mlp, row, LE);
	      Mlp->orig_upbo[row] = -field6;
	    }
	    else { /* let's be paranoid */
	      fprintf(stderr,
		      "Cannot figure out row type, row = %d, ch_sign = %d, upbo = %g\n",
		      row, Mlp->ch_sign[row], (double)Mlp->orig_upbo[row]);
	    }
	  }
	  
	}
	break;
      }
    }
  }
  return(Mlp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -