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

📄 glpapi01.c

📁 著名的大规模线性规划求解器源码GLPK.C语言版本,可以修剪.内有详细帮助文档.
💻 C
📖 第 1 页 / 共 4 页
字号:
      if (ncs > N_MAX - lp->n)         xerror("glp_add_cols: ncs = %d; too many columns\n", ncs);      n_new = lp->n + ncs;      /* increase the room, if necessary */      if (lp->n_max < n_new)      {  GLPCOL **save = lp->col;         while (lp->n_max < n_new)         {  lp->n_max += lp->n_max;            xassert(lp->n_max > 0);         }         lp->col = xcalloc(1+lp->n_max, sizeof(GLPCOL *));         memcpy(&lp->col[1], &save[1], lp->n * sizeof(GLPCOL *));         xfree(save);      }      /* add new columns to the end of the column list */      for (j = lp->n+1; j <= n_new; j++)      {  /* create column descriptor */         lp->col[j] = col = dmp_get_atom(lp->pool, sizeof(GLPCOL));         col->j = j;         col->name = NULL;         col->node = NULL;         col->kind = GLP_CV;         col->type = GLP_FX;         col->lb = col->ub = 0.0;         col->coef = 0.0;         col->ptr = NULL;         col->sjj = 1.0;         col->stat = GLP_NS;#if 0         col->bind = -1;#else         col->bind = 0; /* the basis may remain valid */#endif         col->prim = col->dual = 0.0;         col->pval = col->dval = 0.0;         col->mipx = 0.0;      }      /* set new number of columns */      lp->n = n_new;      /* return the ordinal number of the first column added */      return n_new - ncs + 1;}/************************************************************************  NAME**  glp_set_row_name - assign (change) row name**  SYNOPSIS**  void glp_set_row_name(glp_prob *lp, int i, const char *name);**  DESCRIPTION**  The routine glp_set_row_name assigns a given symbolic name (1 up to*  255 characters) to i-th row (auxiliary variable) of the specified*  problem object.**  If the parameter name is NULL or empty string, the routine erases an*  existing name of i-th row. */void glp_set_row_name(glp_prob *lp, int i, const char *name){     glp_tree *tree = lp->tree;      GLPROW *row;      if (!(1 <= i && i <= lp->m))         xerror("glp_set_row_name: i = %d; row number out of range\n",            i);      row = lp->row[i];      if (tree != NULL && tree->reason != 0)      {  xassert(tree->curr != NULL);         xassert(row->level == tree->curr->level);      }      if (row->name != NULL)      {  if (row->node != NULL)         {  xassert(lp->r_tree != NULL);            avl_delete_node(lp->r_tree, row->node);            row->node = NULL;         }         dmp_free_atom(lp->pool, row->name, strlen(row->name)+1);         row->name = NULL;      }      if (!(name == NULL || name[0] == '\0'))      {  int k;         for (k = 0; name[k] != '\0'; k++)         {  if (k == 256)               xerror("glp_set_row_name: i = %d; row name too long\n",                  i);            if (iscntrl((unsigned char)name[k]))               xerror("glp_set_row_name: i = %d: row name contains inva"                  "lid character(s)\n", i);         }         row->name = dmp_get_atom(lp->pool, strlen(name)+1);         strcpy(row->name, name);         if (lp->r_tree != NULL)         {  xassert(row->node == NULL);            row->node = avl_insert_node(lp->r_tree, row->name);            avl_set_node_link(row->node, row);         }      }      return;}/************************************************************************  NAME**  glp_set_col_name - assign (change) column name**  SYNOPSIS**  void glp_set_col_name(glp_prob *lp, int j, const char *name);**  DESCRIPTION**  The routine glp_set_col_name assigns a given symbolic name (1 up to*  255 characters) to j-th column (structural variable) of the specified*  problem object.**  If the parameter name is NULL or empty string, the routine erases an*  existing name of j-th column. */void glp_set_col_name(glp_prob *lp, int j, const char *name){     glp_tree *tree = lp->tree;      GLPCOL *col;      if (tree != NULL && tree->reason != 0)         xerror("glp_set_col_name: operation not allowed\n");      if (!(1 <= j && j <= lp->n))         xerror("glp_set_col_name: j = %d; column number out of range\n"            , j);      col = lp->col[j];      if (col->name != NULL)      {  if (col->node != NULL)         {  xassert(lp->c_tree != NULL);            avl_delete_node(lp->c_tree, col->node);            col->node = NULL;         }         dmp_free_atom(lp->pool, col->name, strlen(col->name)+1);         col->name = NULL;      }      if (!(name == NULL || name[0] == '\0'))      {  int k;         for (k = 0; name[k] != '\0'; k++)         {  if (k == 256)               xerror("glp_set_col_name: j = %d; column name too long\n"                  , j);            if (iscntrl((unsigned char)name[k]))               xerror("glp_set_col_name: j = %d: column name contains i"                  "nvalid character(s)\n", j);         }         col->name = dmp_get_atom(lp->pool, strlen(name)+1);         strcpy(col->name, name);         if (lp->c_tree != NULL && col->name != NULL)         {  xassert(col->node == NULL);            col->node = avl_insert_node(lp->c_tree, col->name);            avl_set_node_link(col->node, col);         }      }      return;}/************************************************************************  NAME**  glp_set_row_bnds - set (change) row bounds**  SYNOPSIS**  void glp_set_row_bnds(glp_prob *lp, int i, int type, double lb,*     double ub);**  DESCRIPTION**  The routine glp_set_row_bnds sets (changes) the type and bounds of*  i-th row (auxiliary variable) of the specified problem object.**  Parameters type, lb, and ub specify the type, lower bound, and upper*  bound, respectively, as follows:**     Type           Bounds        Comments*     ------------------------------------------------------*     GLP_FR   -inf <  x <  +inf   Free variable*     GLP_LO     lb <= x <  +inf   Variable with lower bound*     GLP_UP   -inf <  x <=  ub    Variable with upper bound*     GLP_DB     lb <= x <=  ub    Double-bounded variable*     GLP_FX           x  =  lb    Fixed variable**  where x is the auxiliary variable associated with i-th row.**  If the row has no lower bound, the parameter lb is ignored. If the*  row has no upper bound, the parameter ub is ignored. If the row is*  an equality constraint (i.e. the corresponding auxiliary variable is*  of fixed type), only the parameter lb is used while the parameter ub*  is ignored. */void glp_set_row_bnds(glp_prob *lp, int i, int type, double lb,      double ub){     GLPROW *row;      if (!(1 <= i && i <= lp->m))         xerror("glp_set_row_bnds: i = %d; row number out of range\n",            i);      row = lp->row[i];      row->type = type;      switch (type)      {  case GLP_FR:            row->lb = row->ub = 0.0;            if (row->stat != GLP_BS) row->stat = GLP_NF;            break;         case GLP_LO:            row->lb = lb, row->ub = 0.0;            if (row->stat != GLP_BS) row->stat = GLP_NL;            break;         case GLP_UP:            row->lb = 0.0, row->ub = ub;            if (row->stat != GLP_BS) row->stat = GLP_NU;            break;         case GLP_DB:            row->lb = lb, row->ub = ub;            if (!(row->stat == GLP_BS ||                  row->stat == GLP_NL || row->stat == GLP_NU))               row->stat = (fabs(lb) <= fabs(ub) ? GLP_NL : GLP_NU);            break;         case GLP_FX:            row->lb = row->ub = lb;            if (row->stat != GLP_BS) row->stat = GLP_NS;            break;         default:            xerror("glp_set_row_bnds: i = %d; type = %d; invalid row ty"               "pe\n", i, type);      }      return;}/************************************************************************  NAME**  glp_set_col_bnds - set (change) column bounds**  SYNOPSIS**  void glp_set_col_bnds(glp_prob *lp, int j, int type, double lb,*     double ub);**  DESCRIPTION**  The routine glp_set_col_bnds sets (changes) the type and bounds of*  j-th column (structural variable) of the specified problem object.**  Parameters type, lb, and ub specify the type, lower bound, and upper*  bound, respectively, as follows:**     Type           Bounds        Comments*     ------------------------------------------------------*     GLP_FR   -inf <  x <  +inf   Free variable*     GLP_LO     lb <= x <  +inf   Variable with lower bound*     GLP_UP   -inf <  x <=  ub    Variable with upper bound*     GLP_DB     lb <= x <=  ub    Double-bounded variable*     GLP_FX           x  =  lb    Fixed variable**  where x is the structural variable associated with j-th column.**  If the column has no lower bound, the parameter lb is ignored. If the*  column has no upper bound, the parameter ub is ignored. If the column*  is of fixed type, only the parameter lb is used while the parameter*  ub is ignored. */void glp_set_col_bnds(glp_prob *lp, int j, int type, double lb,      double ub){     GLPCOL *col;      if (!(1 <= j && j <= lp->n))         xerror("glp_set_col_bnds: j = %d; column number out of range\n"            , j);      col = lp->col[j];      col->type = type;      switch (type)      {  case GLP_FR:            col->lb = col->ub = 0.0;            if (col->stat != GLP_BS) col->stat = GLP_NF;            break;         case GLP_LO:            col->lb = lb, col->ub = 0.0;            if (col->stat != GLP_BS) col->stat = GLP_NL;            break;         case GLP_UP:            col->lb = 0.0, col->ub = ub;            if (col->stat != GLP_BS) col->stat = GLP_NU;            break;         case GLP_DB:            col->lb = lb, col->ub = ub;            if (!(col->stat == GLP_BS ||                  col->stat == GLP_NL || col->stat == GLP_NU))               col->stat = (fabs(lb) <= fabs(ub) ? GLP_NL : GLP_NU);            break;         case GLP_FX:            col->lb = col->ub = lb;            if (col->stat != GLP_BS) col->stat = GLP_NS;            break;         default:            xerror("glp_set_col_bnds: j = %d; type = %d; invalid column"               " type\n", j, type);      }      return;}/************************************************************************  NAME**  glp_set_obj_coef - set (change) obj. coefficient or constant term**  SYNOPSIS**  void glp_set_obj_coef(glp_prob *lp, int j, double coef);**  DESCRIPTION**  The routine glp_set_obj_coef sets (changes) objective coefficient at*  j-th column (structural variable) of the specified problem object.**  If the parameter j is 0, the routine sets (changes) the constant term*  ("shift") of the objective function. */void glp_set_obj_coef(glp_prob *lp, int j, double coef){     glp_tree *tree = lp->tree;      if (tree != NULL && tree->reason != 0)         xerror("glp_set_obj_coef: operation not allowed\n");      if (!(0 <= j && j <= lp->n))         xerror("glp_set_obj_coef: j = %d; column number out of range\n"            , j);      if (j == 0)         lp->c0 = coef;      else         lp->col[j]->coef = coef;      return;}/************************************************************************  NAME**  glp_set_mat_row - set (replace) row of the constraint matrix**  SYNOPSIS**  void glp_set_mat_row(glp_prob *lp, int i, int len, const int ind[],*     const double val[]);**  DESCRIPTION**  The routine glp_set_mat_row stores (replaces) the contents of i-th*  row of the constraint matrix of the specified problem object.

⌨️ 快捷键说明

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