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

📄 readmps.c

📁 利用c语言编写
💻 C
📖 第 1 页 / 共 2 页
字号:
            report(Mlp, SEVERE, "Unknown relat '%s' on line %d", field1, Lineno);            FREE(Last_column);	    delete_lp(Mlp);	    return(NULL);	  }	  break;        /* Process entries in the COLUMNS section */	case MPSCOLUMNS:	  /* field2: variable; field3: constraint; field4: coef */	  /* optional: field5: constraint; field6: coef */	  report(Mlp, FULL, "Columns line: %s %s %g %s %g",		 field2, field3, field4, field5, field6);	  if((items == 4) || (items == 6)) {	    if (strcmp(field2, Last_col_name) != 0 && Column_ready) {	      if (!addmpscolumn(Mlp, Int_section, &Column_ready, Last_column, Last_col_name)) {                FREE(Last_column);		delete_lp(Mlp);		return(NULL);	      }	      strcpy(Last_col_name, field2);	      Column_ready = TRUE;	    }	    else {	      strcpy(Last_col_name, field2);	      Column_ready = TRUE;	    }	    if((row = find_row(Mlp, field3, Unconstrained_rows_found)) >= 0) {	      Last_column[row] = (REAL)field4;	    }	  }	  if(items == 6) {	    if((row = find_row(Mlp, field5, Unconstrained_rows_found)) >= 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) {	      if (!addmpscolumn(Mlp, Int_section, &Column_ready, Last_column, Last_col_name)) {                FREE(Last_column);		delete_lp(Mlp);		return(NULL);	      }	      if(strcmp(field5, "'INTORG'") == 0) {		Int_section = TRUE;		report(Mlp, FULL, "Switching to integer section");	      }	      else if(strcmp(field5, "'INTEND'") == 0) {		Int_section = FALSE;		report(Mlp, FULL, "Switching to non-integer section");	      }	      else		report(Mlp, IMPORTANT, "Unknown marker (ignored) at line %d: %s",			Lineno, field5);	    }	  }	  if((items != 4) && (items != 6) && (items != 5)) { /* Wrong! */	    report(Mlp, CRITICAL, "Wrong number of items (%d) in COLUMNS section (line %d)",		    items, Lineno);            FREE(Last_column);	    delete_lp(Mlp);	    return(NULL);	  }	  break;        /* Process entries in the RHS section */        /* field2: uninteresting name; field3: constraint name */        /* field4: value */        /* optional: field5: constraint name; field6: value */	case MPSRHS:	  report(Mlp, FULL, "RHS line: %s %s %g %s %g",		   field2, field3, field4, field5, field6);	  if((items != 4) && (items != 6)) {	    report(Mlp, CRITICAL, "Wrong number of items (%d) in RHS section line %d",		    items, Lineno);            FREE(Last_column);	    delete_lp(Mlp);	    return(NULL);	  }	  if((row = find_row(Mlp, field3, Unconstrained_rows_found)) >= 0) {	    set_rh(Mlp, row, (REAL)field4);	  }	  if(items == 6) {	    if((row = find_row(Mlp, field5, Unconstrained_rows_found)) >= 0) {	      set_rh(Mlp, row, (REAL)field6);	    }	  }	  break;        /* Process entries in the BOUNDS section */        /* field1: bound type; field2: uninteresting name; */        /* field3: variable name; field4: value */        case MPSBOUNDS:	  report(Mlp, FULL, "BOUNDS line: %s %s %s %g",		 field1, field2, field3, field4);	  var = find_var(Mlp, field3, FALSE);	  if(var < 0){ /* bound on undefined var in COLUMNS section ... */	    Column_ready = TRUE;	    if (!addmpscolumn(Mlp, FALSE, &Column_ready, Last_column, field3)) {	      FREE(Last_column);	      delete_lp(Mlp);	      return(NULL);	    }	    Column_ready = TRUE;	    var = find_var(Mlp, field3, TRUE);	  }	  if(var < 0) /* undefined var and could add ... */;	  else if(strcmp(field1, "UP") == 0) {	    /* upper bound */	    set_bounds(Mlp, var, get_lowbo(Mlp, var), field4);	  }	  else if(strcmp(field1, "SC") == 0) {	    /* upper bound */	    set_bounds(Mlp, var, get_lowbo(Mlp, var), field4);    	    set_semicont(Mlp, var, TRUE);	  }	  else if(strcmp(field1, "SI") == 0) {	    /* upper bound */	    set_bounds(Mlp, var, get_lowbo(Mlp, var), field4);	    set_int(Mlp, var, TRUE);    	    set_semicont(Mlp, var, TRUE);	  }	  else if(strcmp(field1, "LO") == 0) {	    /* lower bound */	    set_bounds(Mlp, var, field4, get_upbo(Mlp, var));	  }	  else if(strcmp(field1, "PL") == 0)   /* plus-ranged variable */	    /* normal, 0 <= var <= inf, do nothing */;	  else if(strcmp(field1, "MI") == 0) { /* minus-ranged variable */	    set_bounds(Mlp, var, -DEF_INFINITE, 0);	  }	  else if(strcmp(field1, "FR") == 0) { /* free variable */	    set_bounds(Mlp, var, -Mlp->infinite, Mlp->infinite);	  }	  else if(strcmp(field1, "FX") == 0) {	    /* fixed, upper _and_ lower  */	    set_bounds(Mlp, var, field4, field4);	  }	  else if(strcmp(field1, "BV") == 0) { /* binary variable */	    set_bounds(Mlp, var, 0, 1);	    set_int(Mlp, var, TRUE);	  }	  /* AMPL bounds type UI and LI added by E.Imamura (CRIEPI)  */	  else if(strcmp(field1, "UI") == 0) { /* upper bound for integer variable */	    set_bounds(Mlp, var, get_lowbo(Mlp, var), field4);	    set_int(Mlp, var, TRUE);	  }	  else if(strcmp(field1, "LI") == 0) { /* lower bound for integer variable - corrected by KE */	    set_bounds(Mlp, var, field4, get_upbo(Mlp, var));	    set_int(Mlp, var, TRUE);	  }#if 0	  /* hack for free and negative variables. Ugly, and does not	     always work. MB */	  else if(strcmp(field1, "FR") == 0) { /* free variable */	    report(Mlp, NORMAL,		    "Free variable %s is split in a positive part %s and a negative part %s_",		    field3, field3, field3);	    strcat(field3, "_");	    get_column(Mlp, var, Last_column);	    for (i = 0; i <= Mlp->rows; i++)	      Last_column[i]*=-1;	    if ((!add_column(Mlp, Last_column)) || (!set_col_name(Mlp, Mlp->columns, field3))) {              FREE(Last_column);	      delete_lp(Mlp);	      return(NULL);	    }	    /* 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 */	    report(Mlp, NORMAL,		    "Negative variable %s will be represented by - %s-",		    field3, field3);	    get_column(Mlp, var, Last_column);	    del_column(Mlp, var);	    strcat(field3, "-");	    for (i = 0; i <= Mlp->rows; i++)	      Last_column[i] *= -1;	    if ((!add_column(Mlp, Last_column)) || (!set_row_name(Mlp, var, field3))) {              FREE(Last_column);	      delete_lp(Mlp);	      return(NULL);	    }	    /* should lower and upper bounds of variable be adjusted? What if	       lower and upper bound are specified later? (does not work!) MB */	  }#endif	  else {	    report(Mlp, CRITICAL, "BOUND type %s on line %d is not supported",		   field1, Lineno);            FREE(Last_column);	    delete_lp(Mlp);	    return(NULL);	  }	  break;        /* Process entries in the BOUNDS section */	/* 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 */	  case MPSRANGES:	  report(Mlp, FULL, "RANGES line: %s %s %g %s %g",		 field2, field3, field4, field5, field6);	  if((items != 4) && (items != 6)) {	    report(Mlp, CRITICAL, "Wrong number of items (%d) in RANGES section line %d",		   items, Lineno);            FREE(Last_column);	    delete_lp(Mlp);	    return(NULL);	  }	  if(((row = find_row(Mlp, field3, Unconstrained_rows_found)) >= 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) {	      report(Mlp, IMPORTANT,		     "Warning, Range for row %s >= infinity (value %g) on line %d, ignored",		     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 */	      report(Mlp, IMPORTANT,		      "Cannot figure out row type, row = %d, ch_sign = %d, upbo = %g",		      row, Mlp->ch_sign[row], (double)Mlp->orig_upbo[row]);	    }	  }	  if(items == 6) {	    if(((row = find_row(Mlp, field5, Unconstrained_rows_found)) >= 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) {		report(Mlp, IMPORTANT,			"Warning, Range for row %s >= infinity (value %g) on line %d, ignored",			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 */		report(Mlp, IMPORTANT,			"Cannot figure out row type, row = %d, ch_sign = %d, upbo = %g",			row, Mlp->ch_sign[row], (double)Mlp->orig_upbo[row]);	      }	    }	  }          break;        /* Process entries in the SOS section */        /* We have to implement the following semantics:          E. The SOS section is for ordered variable sets of the form:  	      x1, x2, x3 ... xn where only a given number of consequtive variables          may be non-zero.  Each set definition is prefaced by type, name  	      and priority data.  Each set member has an optional weight that  	      determines its order.  There are two forms supported; a full format  	      and a reduced CPLEX-like format.                                       */        case MPSSOS:          report(Mlp, FULL, "SOS line: %s %s %g %s %g",                 field2, field3, field4, field5, field6);          if((items == 0) || (items > 4)) {            report(Mlp, IMPORTANT,                   "Invalid number of items (%d) in SOS section line %d\n",                   items, Lineno);            FREE(Last_column);   /* Added by KE */            delete_lp(Mlp);            return(NULL);  	  }          if(strlen(field1) == 0) items--;  /* fix scanline anomoly! */          if(items == 1 || items == 4) {  	    if(strcmp(field1, "S1") == 0)        /* SOS1 */              row = 1;            else if(strcmp(field1, "S2") == 0)   /* SOS2 */              row = 2;	    else {              report(Mlp, IMPORTANT,                     "Error: Invalid SOS type %s line %d\n", field1, Lineno);              FREE(Last_column);   /* Added by KE */              delete_lp(Mlp);              return(NULL);            }            field1[0] = '\0';               /* fix scanline anomoly! */	    /* lp_solve prefers a name for the SOS */	    if(strlen(field3) == 0)	      sprintf(field3, "SOS_%d", Mlp->sos_count + 1);	    if(items == 4)	      SOS = (int) (field4 + .1);	    else	      SOS = 1;	    SOS = add_SOS(Mlp, field3, (short) row, SOS, 0, NULL, NULL);  	  }          else {	    char *field = (items == 3) ? field3 : field2;            var = find_var(Mlp, field, FALSE);	    if(var < 0){ /* SOS on undefined var in COLUMNS section ... */	      Column_ready = TRUE;	      if (!addmpscolumn(Mlp, FALSE, &Column_ready, Last_column, field)) {		FREE(Last_column);		delete_lp(Mlp);		return(NULL);	      }	      Column_ready = TRUE;	      var = find_var(Mlp, field, TRUE);	    }	    if(var < 0) /* undefined var and could add ... */;            else append_SOSrec(Mlp, Mlp->sos_list[SOS-1], 1, &var, &field4);  	  }          break;        }      }    }    FREE(Last_column);  }  return(Mlp);}

⌨️ 快捷键说明

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