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

📄 glpapi01.c

📁 著名的大规模线性规划求解器源码GLPK.C语言版本,可以修剪.内有详细帮助文档.
💻 C
📖 第 1 页 / 共 4 页
字号:
               else                  next->r_prev = aij->r_prev;               /* remove the element from the column list */               if (aij->c_prev == NULL)                  aij->col->ptr = aij->c_next;               else                  aij->c_prev->c_next = aij->c_next;               if (aij->c_next == NULL)                  ;               else                  aij->c_next->c_prev = aij->c_prev;               /* return the element to the memory pool */               dmp_free_atom(lp->pool, aij, sizeof(GLPAIJ)), lp->nnz--;            }         }      }      /* invalidate the basis factorization */      lp->valid = 0;      return;}/************************************************************************  NAME**  glp_del_rows - delete rows from problem object**  SYNOPSIS**  void glp_del_rows(glp_prob *lp, int nrs, const int num[]);**  DESCRIPTION**  The routine glp_del_rows deletes rows from the specified problem*  object. Ordinal numbers of rows to be deleted should be placed in*  locations num[1], ..., num[nrs], where nrs > 0.**  Note that deleting rows involves changing ordinal numbers of other*  rows remaining in the problem object. New ordinal numbers of the*  remaining rows are assigned under the assumption that the original*  order of rows is not changed. */void glp_del_rows(glp_prob *lp, int nrs, const int num[]){     glp_tree *tree = lp->tree;      GLPROW *row;      int i, k, m_new;      /* mark rows to be deleted */      if (!(1 <= nrs && nrs <= lp->m))         xerror("glp_del_rows: nrs = %d; invalid number of rows\n",            nrs);      for (k = 1; k <= nrs; k++)      {  /* take the number of row to be deleted */         i = num[k];         /* obtain pointer to i-th row */         if (!(1 <= i && i <= lp->m))            xerror("glp_del_rows: num[%d] = %d; row number out of range"               "\n", k, i);         row = lp->row[i];         if (tree != NULL && tree->reason != 0)         {  xassert(tree->curr != NULL);            xassert(row->level == tree->curr->level);         }         /* check that the row is not marked yet */         if (row->i == 0)            xerror("glp_del_rows: num[%d] = %d; duplicate row numbers n"               "ot allowed\n", k, i);         /* erase symbolic name assigned to the row */         glp_set_row_name(lp, i, NULL);         xassert(row->node == NULL);         /* erase corresponding row of the constraint matrix */         glp_set_mat_row(lp, i, 0, NULL, NULL);         xassert(row->ptr == NULL);         /* mark the row to be deleted */         row->i = 0;      }      /* delete all marked rows from the row list */      m_new = 0;      for (i = 1; i <= lp->m; i++)      {  /* obtain pointer to i-th row */         row = lp->row[i];         /* check if the row is marked */         if (row->i == 0)         {  /* it is marked, delete it */            dmp_free_atom(lp->pool, row, sizeof(GLPROW));         }         else         {  /* it is not marked; keep it */            row->i = ++m_new;            lp->row[row->i] = row;         }      }      /* set new number of rows */      lp->m = m_new;      /* invalidate the basis factorization */      lp->valid = 0;      return;}/************************************************************************  NAME**  glp_del_cols - delete columns from problem object**  SYNOPSIS**  void glp_del_cols(glp_prob *lp, int ncs, const int num[]);**  DESCRIPTION**  The routine glp_del_cols deletes columns from the specified problem*  object. Ordinal numbers of columns to be deleted should be placed in*  locations num[1], ..., num[ncs], where ncs > 0.**  Note that deleting columns involves changing ordinal numbers of*  other columns remaining in the problem object. New ordinal numbers*  of the remaining columns are assigned under the assumption that the*  original order of columns is not changed. */void glp_del_cols(glp_prob *lp, int ncs, const int num[]){     glp_tree *tree = lp->tree;      GLPCOL *col;      int j, k, n_new;      if (tree != NULL && tree->reason != 0)         xerror("glp_del_cols: operation not allowed\n");      /* mark columns to be deleted */      if (!(1 <= ncs && ncs <= lp->n))         xerror("glp_del_cols: ncs = %d; invalid number of columns\n",            ncs);      for (k = 1; k <= ncs; k++)      {  /* take the number of column to be deleted */         j = num[k];         /* obtain pointer to j-th column */         if (!(1 <= j && j <= lp->n))            xerror("glp_del_cols: num[%d] = %d; column number out of ra"               "nge", k, j);         col = lp->col[j];         /* check that the column is not marked yet */         if (col->j == 0)            xerror("glp_del_cols: num[%d] = %d; duplicate column number"               "s not allowed\n", k, j);         /* erase symbolic name assigned to the column */         glp_set_col_name(lp, j, NULL);         xassert(col->node == NULL);         /* erase corresponding column of the constraint matrix */         glp_set_mat_col(lp, j, 0, NULL, NULL);         xassert(col->ptr == NULL);         /* mark the column to be deleted */         col->j = 0;         /* if it is basic, invalidate the basis factorization */         if (col->stat == GLP_BS) lp->valid = 0;      }      /* delete all marked columns from the column list */      n_new = 0;      for (j = 1; j <= lp->n; j++)      {  /* obtain pointer to j-th column */         col = lp->col[j];         /* check if the column is marked */         if (col->j == 0)         {  /* it is marked; delete it */            dmp_free_atom(lp->pool, col, sizeof(GLPCOL));         }         else         {  /* it is not marked; keep it */            col->j = ++n_new;            lp->col[col->j] = col;         }      }      /* set new number of columns */      lp->n = n_new;      /* if the basis header is still valid, adjust it */      if (lp->valid)      {  int m = lp->m;         int *head = lp->head;         for (j = 1; j <= n_new; j++)         {  k = lp->col[j]->bind;            if (k != 0)            {  xassert(1 <= k && k <= m);               head[k] = m + j;            }         }      }      return;}/************************************************************************  NAME**  glp_copy_prob - copy problem object content**  SYNOPSIS**  void glp_copy_prob(glp_prob *dest, glp_prob *prob, int names);**  DESCRIPTION**  The routine glp_copy_prob copies the content of the problem object*  prob to the problem object dest.**  The parameter names is a flag. If it is non-zero, the routine also*  copies all symbolic names; otherwise, if it is zero, symbolic names*  are not copied. */void glp_copy_prob(glp_prob *dest, glp_prob *prob, int names){     glp_tree *tree = dest->tree;      glp_bfcp bfcp;      int i, j, len, *ind;      double *val;      if (tree != NULL && tree->reason != 0)         xerror("glp_copy_prob: operation not allowed\n");      if (dest == prob)         xerror("glp_copy_prob: copying problem object to itself not al"            "lowed\n");      if (!(names == GLP_ON || names == GLP_OFF))         xerror("glp_copy_prob: names = %d; invalid parameter\n",            names);      glp_erase_prob(dest);      if (names && prob->name != NULL)         glp_set_prob_name(dest, prob->name);      if (names && prob->obj != NULL)         glp_set_obj_name(dest, prob->obj);      dest->dir = prob->dir;      dest->c0 = prob->c0;      if (prob->m > 0)         glp_add_rows(dest, prob->m);      if (prob->n > 0)         glp_add_cols(dest, prob->n);      glp_get_bfcp(prob, &bfcp);      glp_set_bfcp(dest, &bfcp);      dest->pbs_stat = prob->pbs_stat;      dest->dbs_stat = prob->dbs_stat;      dest->obj_val = prob->obj_val;      dest->some = prob->some;      dest->ipt_stat = prob->ipt_stat;      dest->ipt_obj = prob->ipt_obj;      dest->mip_stat = prob->mip_stat;      dest->mip_obj = prob->mip_obj;      for (i = 1; i <= prob->m; i++)      {  GLPROW *to = dest->row[i];         GLPROW *from = prob->row[i];         if (names && from->name != NULL)            glp_set_row_name(dest, i, from->name);         to->type = from->type;         to->lb = from->lb;         to->ub = from->ub;         to->rii = from->rii;         to->stat = from->stat;         to->prim = from->prim;         to->dual = from->dual;         to->pval = from->pval;         to->dval = from->dval;         to->mipx = from->mipx;      }      ind = xcalloc(1+prob->m, sizeof(int));      val = xcalloc(1+prob->m, sizeof(double));      for (j = 1; j <= prob->n; j++)      {  GLPCOL *to = dest->col[j];         GLPCOL *from = prob->col[j];         if (names && from->name != NULL)            glp_set_col_name(dest, j, from->name);         to->kind = from->kind;         to->type = from->type;         to->lb = from->lb;         to->ub = from->ub;         to->coef = from->coef;         len = glp_get_mat_col(prob, j, ind, val);         glp_set_mat_col(dest, j, len, ind, val);         to->sjj = from->sjj;         to->stat = from->stat;         to->prim = from->prim;         to->dual = from->dual;         to->pval = from->pval;         to->dval = from->dval;         to->mipx = from->mipx;      }      xfree(ind);      xfree(val);      return;}/************************************************************************  NAME**  glp_erase_prob - erase problem object content**  SYNOPSIS**  void glp_erase_prob(glp_prob *lp);**  DESCRIPTION**  The routine glp_erase_prob erases the content of the specified*  problem object. The effect of this operation is the same as if the*  problem object would be deleted with the routine glp_delete_prob and*  then created anew with the routine glp_create_prob, with exception*  that the handle (pointer) to the problem object remains valid. */static void delete_prob(glp_prob *lp);void glp_erase_prob(glp_prob *lp){     glp_tree *tree = lp->tree;      if (tree != NULL && tree->reason != 0)         xerror("glp_erase_prob: operation not allowed\n");      delete_prob(lp);      create_prob(lp);      return;}/************************************************************************  NAME**  glp_delete_prob - delete problem object**  SYNOPSIS**  void glp_delete_prob(glp_prob *lp);**  DESCRIPTION**  The routine glp_delete_prob deletes the specified problem object and*  frees all the memory allocated to it. */static void delete_prob(glp_prob *lp){     dmp_delete_pool(lp->pool);      xfree(lp->cps);      xassert(lp->tree == NULL);      if (lp->cwa != NULL) xfree(lp->cwa);      xfree(lp->row);      xfree(lp->col);      if (lp->r_tree != NULL) avl_delete_tree(lp->r_tree);      if (lp->c_tree != NULL) avl_delete_tree(lp->c_tree);      xfree(lp->head);      if (lp->bfcp != NULL) xfree(lp->bfcp);      if (lp->bfd != NULL) bfd_delete_it(lp->bfd);      return;}void glp_delete_prob(glp_prob *lp){     glp_tree *tree = lp->tree;      if (tree != NULL && tree->reason != 0)         xerror("glp_delete_prob: operation not allowed\n");      delete_prob(lp);      xfree(lp);      return;}/* eof */

⌨️ 快捷键说明

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