📄 glpmpl04.c
字号:
return len;}/*------------------------------------------------------------------------ mpl_get_row_c0 - obtain constant term of free row.---- *Synopsis*---- #include "glpmpl.h"-- double mpl_get_row_c0(MPL *mpl, int i);---- *Returns*---- The routine mpl_get_row_c0 returns numeric value of constant term of-- i-th row.---- Note that only free rows may have non-zero constant terms. Therefore-- if i-th row is not free, the routine returns zero. */double mpl_get_row_c0(MPL *mpl, int i){ ELEMCON *con; double c0; if (mpl->phase != 3) xfault("mpl_get_row_c0: invalid call sequence\n"); if (!(1 <= i && i <= mpl->m)) xfault("mpl_get_row_c0: i = %d; row number out of range\n", i); con = mpl->row[i]; if (con->con->lbnd == NULL && con->con->ubnd == NULL) c0 = - con->lbnd; else c0 = 0.0; return c0;}/*------------------------------------------------------------------------ mpl_get_col_name - obtain column name.---- *Synopsis*---- #include "glpmpl.h"-- char *mpl_get_col_name(MPL *mpl, int j);---- *Returns*---- The routine mpl_get_col_name returns a pointer to internal buffer,-- which contains symbolic name of j-th column of the problem. */char *mpl_get_col_name(MPL *mpl, int j){ char *name = mpl->mpl_buf, *t; int len; if (mpl->phase != 3) xfault("mpl_get_col_name: invalid call sequence\n"); if (!(1 <= j && j <= mpl->n)) xfault("mpl_get_col_name: j = %d; column number out of range\n" , j); strcpy(name, mpl->col[j]->var->name); len = strlen(name); xassert(len <= 255); t = format_tuple(mpl, '[', mpl->col[j]->memb->tuple); while (*t) { if (len == 255) break; name[len++] = *t++; } name[len] = '\0'; if (len == 255) strcpy(name+252, "..."); xassert(strlen(name) <= 255); return name;}/*------------------------------------------------------------------------ mpl_get_col_kind - determine column kind.---- *Synopsis*---- #include "glpmpl.h"-- int mpl_get_col_kind(MPL *mpl, int j);---- *Returns*---- The routine mpl_get_col_kind returns the kind of j-th column, which-- can be one of the following:---- MPL_NUM - continuous variable;-- MPL_INT - integer variable;-- MPL_BIN - binary variable.---- Note that column kinds are defined independently on type and bounds-- (reported by the routine mpl_get_col_bnds) of corresponding columns.-- This means, in particular, that bounds of an integer column may be-- fractional, or a binary column may have lower and upper bounds that-- are not 0 and 1 (or it may have no lower/upper bound at all). */int mpl_get_col_kind(MPL *mpl, int j){ int kind; if (mpl->phase != 3) xfault("mpl_get_col_kind: invalid call sequence\n"); if (!(1 <= j && j <= mpl->n)) xfault("mpl_get_col_kind: j = %d; column number out of range\n" , j); switch (mpl->col[j]->var->type) { case A_NUMERIC: kind = MPL_NUM; break; case A_INTEGER: kind = MPL_INT; break; case A_BINARY: kind = MPL_BIN; break; default: xassert(mpl != mpl); } return kind;}/*------------------------------------------------------------------------ mpl_get_col_bnds - obtain column bounds.---- *Synopsis*---- #include "glpmpl.h"-- int mpl_get_col_bnds(MPL *mpl, int j, double *lb, double *ub);---- *Description*---- The routine mpl_get_col_bnds stores lower and upper bound of j-th-- column of the problem to the locations, which the parameters lb and-- ub point to, respectively. Besides the routine returns the type of-- the j-th column.---- If some of the parameters lb and ub is NULL, the corresponding bound-- value is not stored.---- Types and bounds have the following meaning:---- Type Bounds Note-- -------------------------------------------------------- MPL_FR -inf < x < +inf Free (unbounded) variable-- MPL_LO lb <= x < +inf Variable with lower bound-- MPL_UP -inf < x <= ub Variable with upper bound-- MPL_DB lb <= x <= ub Double-bounded variable-- MPL_FX x = lb Fixed variable---- where x is individual variable corresponding to the j-th column.---- If the column has no lower bound, *lb is set to zero; if the column-- has no upper bound, *ub is set to zero; and if the column is of fixed-- type, both *lb and *ub are set to the same value.---- *Returns*---- The routine returns the type of the j-th column as it is stated in-- the table above. */int mpl_get_col_bnds(MPL *mpl, int j, double *_lb, double *_ub){ ELEMVAR *var; int type; double lb, ub; if (mpl->phase != 3) xfault("mpl_get_col_bnds: invalid call sequence\n"); if (!(1 <= j && j <= mpl->n)) xfault("mpl_get_col_bnds: j = %d; column number out of range\n" , j); var = mpl->col[j];#if 0 /* 21/VII-2006 */ if (var->var->lbnd == NULL && var->var->ubnd == NULL) type = MPL_FR, lb = ub = 0.0; else if (var->var->ubnd == NULL) type = MPL_LO, lb = var->lbnd, ub = 0.0; else if (var->var->lbnd == NULL) type = MPL_UP, lb = 0.0, ub = var->ubnd; else if (var->var->lbnd != var->var->ubnd) type = MPL_DB, lb = var->lbnd, ub = var->ubnd; else type = MPL_FX, lb = ub = var->lbnd;#else lb = (var->var->lbnd == NULL ? -DBL_MAX : var->lbnd); ub = (var->var->ubnd == NULL ? +DBL_MAX : var->ubnd); if (lb == -DBL_MAX && ub == +DBL_MAX) type = MPL_FR, lb = ub = 0.0; else if (ub == +DBL_MAX) type = MPL_LO, ub = 0.0; else if (lb == -DBL_MAX) type = MPL_UP, lb = 0.0; else if (var->var->lbnd != var->var->ubnd) type = MPL_DB; else type = MPL_FX;#endif if (_lb != NULL) *_lb = lb; if (_ub != NULL) *_ub = ub; return type;}/*------------------------------------------------------------------------ mpl_has_solve_stmt - check if model has solve statement.---- *Synopsis*---- #include "glpmpl.h"-- int mpl_has_solve_stmt(MPL *mpl);---- *Returns*---- If the model has the solve statement, the routine returns non-zero,-- otherwise zero is returned. */int mpl_has_solve_stmt(MPL *mpl){ if (mpl->phase != 3) xfault("mpl_has_solve_stmt: invalid call sequence\n"); return mpl->flag_s;}/*------------------------------------------------------------------------ mpl_put_col_value - store column value.---- *Synopsis*---- #include "glpmpl.h"-- void mpl_put_col_value(MPL *mpl, int j, double val);---- *Description*---- The routine mpl_put_col_value stores numeric value of j-th column-- into the translator database. It is assumed that the column value is-- provided by the solver. */void mpl_put_col_value(MPL *mpl, int j, double val){ if (mpl->phase != 3) xfault("mpl_put_col_value: invalid call sequence\n"); if (!(1 <= j && j <= mpl->n)) xfault( "mpl_put_col_value: j = %d; column number out of range\n", j); mpl->col[j]->value = val; return;}/*------------------------------------------------------------------------ mpl_postsolve - postsolve model.---- *Synopsis*---- #include "glpmpl.h"-- int mpl_postsolve(MPL *mpl);---- *Description*---- The routine mpl_postsolve performs postsolving of the model using-- its description stored in the translator database. This phase means-- executing statements, which follow the solve statement.---- If this routine is used, it should be called once after the routine-- mpl_generate and if the latter returned the code 3.---- *Returns*---- The routine mpl_postsolve returns one of the following codes:---- 3 - model has been successfully postsolved.-- 4 - processing failed due to some errors. In this case the calling-- program should call the routine mpl_terminate to terminate model-- processing. */int mpl_postsolve(MPL *mpl){ if (!(mpl->phase == 3 && !mpl->flag_p)) xfault("mpl_postsolve: invalid call sequence\n"); /* set up error handler */ if (setjmp(mpl->jump)) goto done; /* perform postsolving */ postsolve_model(mpl); flush_output(mpl); /* postsolving phase has been finished */ xprintf("Model has been successfully processed\n");done: /* return to the calling program */ return mpl->phase;}/*------------------------------------------------------------------------ mpl_terminate - free all resources used by translator.---- *Synopsis*---- #include "glpmpl.h"-- void mpl_terminate(MPL *mpl);---- *Description*---- The routine mpl_terminate frees all the resources used by the GNU-- MathProg translator. */void mpl_terminate(MPL *mpl){ if (setjmp(mpl->jump)) xassert(mpl != mpl); switch (mpl->phase) { case 0: case 1: case 2: case 3: /* there were no errors; clean the model content */ clean_model(mpl); xassert(mpl->a_list == NULL);#if 1 /* 11/II-2008 */ xassert(mpl->dca == NULL);#endif break; case 4: /* model processing has been finished due to error; delete search trees, which may be created for some arrays */ { ARRAY *a; for (a = mpl->a_list; a != NULL; a = a->next) if (a->tree != NULL) avl_delete_tree(a->tree); }#if 1 /* 11/II-2008 */ free_dca(mpl);#endif break; default: xassert(mpl != mpl); } /* delete the translator database */ xfree(mpl->image); xfree(mpl->b_image); xfree(mpl->f_image); xfree(mpl->context); dmp_delete_pool(mpl->pool); avl_delete_tree(mpl->tree); dmp_delete_pool(mpl->strings); dmp_delete_pool(mpl->symbols); dmp_delete_pool(mpl->tuples); dmp_delete_pool(mpl->arrays); dmp_delete_pool(mpl->members); dmp_delete_pool(mpl->elemvars); dmp_delete_pool(mpl->formulae); dmp_delete_pool(mpl->elemcons); xfree(mpl->sym_buf); xfree(mpl->tup_buf); rng_delete_rand(mpl->rand); if (mpl->row != NULL) xfree(mpl->row); if (mpl->col != NULL) xfree(mpl->col); if (mpl->in_fp != NULL) fclose(mpl->in_fp); if (mpl->out_fp != NULL && mpl->out_fp != stdout) fclose(mpl->out_fp); if (mpl->out_file != NULL) xfree(mpl->out_file); if (mpl->out_buf != NULL) xfree(mpl->out_buf);#if 1 /* 14/VII-2006 */ if (mpl->prt_fp != NULL) fclose(mpl->prt_fp); if (mpl->prt_file != NULL) xfree(mpl->prt_file);#endif if (mpl->mod_file != NULL) xfree(mpl->mod_file); xfree(mpl->mpl_buf); xfree(mpl); return;}/* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -