Ejemplo n.º 1
0
int mpq_ILLmps_next_line (mpq_ILLread_mps_state * state)
{
    int rval = 0;
    /* if field 3 or 5 start with $ rest of line is interpreted as comment */
    state->line[0] = '\0';
    state->p = 0;
    while (mpq_ILLline_reader_get (state->line, ILL_namebufsize - 2, state->file)
	!= 0) {
	state->line_num++;
	state->key[0] = '\0';
	state->field[0] = '\0';
	state->field_num = 1;
	state->p = state->line;
	if (!mpq_ILL_ISBLANK ((state->line))) {
	    if (state->line[0] == '*' || state->line[0] == '\n') {
		continue;	/* comment or blank line */
	    } else {
		if (sscanf (state->p, "%s", state->key) == 1) {
		    state->p += strlen (state->key);
		    while (mpq_ILL_ISBLANK (state->p)) {
			state->p++;
		    }
		    if (sscanf (state->p, "%s", state->field) == 1) {
			state->p += strlen (state->field);
		    } else {
			ILL_FAILfalse (state->field[0] == '\0', "sscanf problem?");
		    }
		} else {
		    ILL_FAILfalse (0, "should almost never happen");
		}
	    }
	} else {
	    while (mpq_ILL_ISBLANK (state->p)) {
		state->p++;
	    }
	    if (sscanf (state->p, "%s", state->field) < 1) {
		continue;	/* nothing more on line */
	    } else {
		if (state->field[0] == '\0') {
		    continue;	/* found empty string */
		}
		state->p += strlen (state->field);
	    }
	}
	return 0;
    }
CLEANUP:
    return 1;			/* end of file */
}
Ejemplo n.º 2
0
int mpq_ILLmps_set_section (mpq_ILLread_mps_state * state,
      const ILLmps_section sec)
{
    int rval = 0;
    ILL_FAILfalse (sec != ILL_MPS_NONE, "must be in a proper section");
    if (state->section[sec]) {
	rval = mpq_ILLmps_error (state, "Two %s sections.\n", mpq_ILLmps_section_name[sec]);
    }
    state->section[sec]++;
    state->active = sec;
CLEANUP:
    ILL_RESULT (rval, "mpq_ILLmps_set_section");
}
Ejemplo n.º 3
0
static void mps_err (
	EGLPNUM_TYPENAME_ILLread_mps_state * state,
	int isError,
	const char *format,
	va_list args)
{
	int rval = 0;
	const char *type = (isError) ? "MPS Error" : "MPS Warning";
	int errtype, slen, at;
	EGLPNUM_TYPENAME_qsformat_error error;
	char error_desc[256];

	ILL_FAILfalse_no_rval (format != 0, "format != 0");
	ILL_FAILfalse_no_rval (format[0] != '\0', "format[0] != '0'");
	ILL_FAILfalse_no_rval (state != 0, "state != 0");
	ILL_FAILfalse_no_rval (state->file != 0, "state->file != 0");

	if (state->p == 0)
	{
		at = -1;
	}
	else
	{
		ILL_FAILfalse (state->p >= state->line, "state->p >= state->line");
		at = state->p - state->line;
	}
	vsprintf (error_desc, format, args);
	slen = strlen (error_desc);
	if ((slen > 0) && error_desc[slen - 1] != '\n')
	{
		error_desc[slen] = '\n';
		error_desc[slen + 1] = '\0';
	}

	if (state->file->error_collector != 0)
	{
		errtype = (isError) ? QS_MPS_FORMAT_ERROR : QS_MPS_FORMAT_WARN;
		EGLPNUM_TYPENAME_ILLformat_error_create (&error, errtype, error_desc,
														(int) (state->line_num), state->line, at);
		EGLPNUM_TYPENAME_ILLformat_error (state->file->error_collector, &error);
		EGLPNUM_TYPENAME_ILLformat_error_delete (&error);
	}
	else
	{
		QSlog("%s %d: %s\t", state->file_name, state->line_num,
								state->line);
		QSlog("%s: %s", type, error_desc);
	}
CLEANUP:
	;
}
Ejemplo n.º 4
0
int EGLPNUM_TYPENAME_ILLraw_add_sos_member (
	EGLPNUM_TYPENAME_rawlpdata * lp,
	int colind)
{
	int rval = 0;

	ILL_FAILfalse (lp->nsos > 0, "we should have called EGLPNUM_TYPENAME_ILLraw_add_sos earlier");
	ILL_FAILtrue (EGLPNUM_TYPENAME_ILLraw_is_mem_other_sos (lp, colind),
								"colind is member of another sos set");

	if (lp->is_sos_member[colind] == -1)
	{
		if (lp->nsos_member >= lp->sos_weight_size)
		{
			lp->sos_weight_size *= 1.3;
			lp->sos_weight_size += 1000;
			if (lp->sos_weight_size < lp->nsos_member + 1)
				lp->sos_weight_size = lp->nsos_member + 1;
			lp->sos_weight = EGrealloc (lp->sos_weight,
																	lp->sos_weight_size * sizeof (double));
			//if (ILLutil_reallocrus_scale ((void **) &lp->sos_weight,
			//                              &lp->sos_weight_size,
			//                              lp->nsos_member + 1, 1.3, sizeof (double)))
			//{
			//  ILL_CLEANUP_IF (rval);
			//}
		}
		if (lp->nsos_member >= lp->sos_col_size)
		{
			lp->sos_col_size *= 1.3;
			lp->sos_col_size += 1000;
			if (lp->sos_col_size < lp->nsos_member + 1)
				lp->sos_col_size = lp->nsos_member + 1;
			lp->sos_col = EGrealloc (lp->sos_col, sizeof (int) * lp->sos_col_size);
			//if (ILLutil_reallocrus_scale ((void **) &lp->sos_col,
			//                              &lp->sos_col_size,
			//                              lp->nsos_member + 1, 1.3, sizeof (int)))
			//{
			//  ILL_CLEANUP_IF (rval);
			//}
		}
		lp->sos_col[lp->nsos_member] = colind;
		lp->sos_set[lp->nsos - 1].nelem++;
		lp->is_sos_member[colind] = lp->nsos - 1;
		lp->nsos_member++;
	}
CLEANUP:
	ILL_RETURN (rval, "EGLPNUM_TYPENAME_ILLraw_add_sos_member");
}
Ejemplo n.º 5
0
int EGLPNUM_TYPENAME_ILLraw_init_ranges (
	EGLPNUM_TYPENAME_rawlpdata * lp)
{
	int i, rval = 0;

	ILL_FAILfalse (lp->rangesind == NULL, "Should be called exactly once");
	if (lp->nrows > 0)
	{
		ILL_SAFE_MALLOC (lp->rangesind, lp->nrows, char);

		for (i = 0; i < lp->nrows; i++)
		{
			lp->rangesind[i] = (char) 0;
		}
	}
Ejemplo n.º 6
0
static char mpq_get_double (mpq_ILLread_mps_state * state,
      int peek,
      mpq_t * coef)
{
    char ok = 0;
    int len, rval = 0;

    ILL_FAILfalse (state != 0, "must have state");
    if (mpq_mps_skip_comment (state))
	return 0;
    len = mpq_ILLget_value (state->p, coef);
    if (len > 0) {
	if (!peek) {
	    state->p += len;
	    state->field_num++;
	}
	ok = 1;
    }
CLEANUP:
    ILL_RESULT (ok, "mpq_get_double");
}
Ejemplo n.º 7
0
static int ILLcheck_rawlpdata (
	EGLPNUM_TYPENAME_rawlpdata * lp)
{
	int i, col, rval = 0;
	int si, *perm = NULL;
	const char *c1, *c2;
	EGLPNUM_TYPENAME_sosptr *set;

	ILL_FAILfalse (lp, "lp must not be NULL");

	/* check    
	 *          *) that there is at least one variable 
	 *          *) that the weights in all SOS sets are distinct 
	 *          *) all sos members are non integer variables     
	 *          *) sos set members have distint weights 
	 *          *) objindex is not -1
	 *          *) INVARIANT: rowname[objindex] != NULL
	 *          *) INVARIANT: upper/lower arrays are filled in 
	 *          *) INVARIANT: if col or rownames != NULL then 
	 *                        all their elements are not NULL
	 */
	if (lp->ncols < 1)
	{
		return EGLPNUM_TYPENAME_ILLdata_error (lp->error_collector, "There are no variables.");
	}
	if (lp->objindex == -1)
	{
		return EGLPNUM_TYPENAME_ILLdata_error (lp->error_collector, "There is no objective fct.");
	}
	ILL_FAILfalse (EGLPNUM_TYPENAME_ILLraw_rowname (lp, lp->objindex) != NULL,
								 "must have objective name");
	if (lp->nsos_member > 1)
	{
		ILL_SAFE_MALLOC (perm, lp->nsos_member, int);

		for (si = 0; si < lp->nsos; si++)
		{
			set = lp->sos_set + si;
			for (i = 0; i < set->nelem; i++)
			{
				col = lp->sos_col[set->first + i];
				if (lp->intmarker[col])
				{
					rval = EGLPNUM_TYPENAME_ILLdata_error (lp->error_collector,
																"SOS set member \"%s\" is an %s.\n",
																EGLPNUM_TYPENAME_ILLraw_colname (lp, col),
																"integer/binary variable");
				}
			}
			if (set->nelem > 1)
			{
				for (i = 0; i < set->nelem; i++)
				{
					perm[i] = set->first + i;
				}
				EGLPNUM_TYPENAME_ILLutil_EGlpNum_perm_quicksort (perm, lp->sos_weight, set->nelem);
				for (i = 1; i < set->nelem; i++)
				{
					if (EGLPNUM_TYPENAME_EGlpNumIsEqqual
							(lp->sos_weight[perm[i - 1]], lp->sos_weight[perm[i]]))
					{
						c1 = EGLPNUM_TYPENAME_ILLraw_colname (lp, lp->sos_col[perm[i]]);
						c2 = EGLPNUM_TYPENAME_ILLraw_colname (lp, lp->sos_col[perm[i - 1]]);
						EGLPNUM_TYPENAME_ILLdata_error (lp->error_collector,
													 "\"%s\" and \"%s\" both have %s %f.\n", c1, c2,
													 "SOS weight", lp->sos_weight[perm[i]]);
						rval = 1;
					}
				}
			}
		}
	}