src/glpnpp01.c
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rw-r--r--
Set up CMAKE build environment
alpar@1
     1
/* glpnpp01.c */
alpar@1
     2
alpar@1
     3
/***********************************************************************
alpar@1
     4
*  This code is part of GLPK (GNU Linear Programming Kit).
alpar@1
     5
*
alpar@1
     6
*  Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@1
     7
*  2009, 2010 Andrew Makhorin, Department for Applied Informatics,
alpar@1
     8
*  Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@1
     9
*  E-mail: <mao@gnu.org>.
alpar@1
    10
*
alpar@1
    11
*  GLPK is free software: you can redistribute it and/or modify it
alpar@1
    12
*  under the terms of the GNU General Public License as published by
alpar@1
    13
*  the Free Software Foundation, either version 3 of the License, or
alpar@1
    14
*  (at your option) any later version.
alpar@1
    15
*
alpar@1
    16
*  GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@1
    17
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@1
    18
*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@1
    19
*  License for more details.
alpar@1
    20
*
alpar@1
    21
*  You should have received a copy of the GNU General Public License
alpar@1
    22
*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@1
    23
***********************************************************************/
alpar@1
    24
alpar@1
    25
#include "glpnpp.h"
alpar@1
    26
alpar@1
    27
NPP *npp_create_wksp(void)
alpar@1
    28
{     /* create LP/MIP preprocessor workspace */
alpar@1
    29
      NPP *npp;
alpar@1
    30
      npp = xmalloc(sizeof(NPP));
alpar@1
    31
      npp->orig_dir = 0;
alpar@1
    32
      npp->orig_m = npp->orig_n = npp->orig_nnz = 0;
alpar@1
    33
      npp->pool = dmp_create_pool();
alpar@1
    34
      npp->name = npp->obj = NULL;
alpar@1
    35
      npp->c0 = 0.0;
alpar@1
    36
      npp->nrows = npp->ncols = 0;
alpar@1
    37
      npp->r_head = npp->r_tail = NULL;
alpar@1
    38
      npp->c_head = npp->c_tail = NULL;
alpar@1
    39
      npp->stack = dmp_create_pool();
alpar@1
    40
      npp->top = NULL;
alpar@1
    41
#if 0 /* 16/XII-2009 */
alpar@1
    42
      memset(&npp->count, 0, sizeof(npp->count));
alpar@1
    43
#endif
alpar@1
    44
      npp->m = npp->n = npp->nnz = 0;
alpar@1
    45
      npp->row_ref = npp->col_ref = NULL;
alpar@1
    46
      npp->sol = npp->scaling = 0;
alpar@1
    47
      npp->p_stat = npp->d_stat = npp->t_stat = npp->i_stat = 0;
alpar@1
    48
      npp->r_stat = NULL;
alpar@1
    49
      /*npp->r_prim =*/ npp->r_pi = NULL;
alpar@1
    50
      npp->c_stat = NULL;
alpar@1
    51
      npp->c_value = /*npp->c_dual =*/ NULL;
alpar@1
    52
      return npp;
alpar@1
    53
}
alpar@1
    54
alpar@1
    55
void npp_insert_row(NPP *npp, NPPROW *row, int where)
alpar@1
    56
{     /* insert row to the row list */
alpar@1
    57
      if (where == 0)
alpar@1
    58
      {  /* insert row to the beginning of the row list */
alpar@1
    59
         row->prev = NULL;
alpar@1
    60
         row->next = npp->r_head;
alpar@1
    61
         if (row->next == NULL)
alpar@1
    62
            npp->r_tail = row;
alpar@1
    63
         else
alpar@1
    64
            row->next->prev = row;
alpar@1
    65
         npp->r_head = row;
alpar@1
    66
      }
alpar@1
    67
      else
alpar@1
    68
      {  /* insert row to the end of the row list */
alpar@1
    69
         row->prev = npp->r_tail;
alpar@1
    70
         row->next = NULL;
alpar@1
    71
         if (row->prev == NULL)
alpar@1
    72
            npp->r_head = row;
alpar@1
    73
         else
alpar@1
    74
            row->prev->next = row;
alpar@1
    75
         npp->r_tail = row;
alpar@1
    76
      }
alpar@1
    77
      return;
alpar@1
    78
}
alpar@1
    79
alpar@1
    80
void npp_remove_row(NPP *npp, NPPROW *row)
alpar@1
    81
{     /* remove row from the row list */
alpar@1
    82
      if (row->prev == NULL)
alpar@1
    83
         npp->r_head = row->next;
alpar@1
    84
      else
alpar@1
    85
         row->prev->next = row->next;
alpar@1
    86
      if (row->next == NULL)
alpar@1
    87
         npp->r_tail = row->prev;
alpar@1
    88
      else
alpar@1
    89
         row->next->prev = row->prev;
alpar@1
    90
      return;
alpar@1
    91
}
alpar@1
    92
alpar@1
    93
void npp_activate_row(NPP *npp, NPPROW *row)
alpar@1
    94
{     /* make row active */
alpar@1
    95
      if (!row->temp)
alpar@1
    96
      {  row->temp = 1;
alpar@1
    97
         /* move the row to the beginning of the row list */
alpar@1
    98
         npp_remove_row(npp, row);
alpar@1
    99
         npp_insert_row(npp, row, 0);
alpar@1
   100
      }
alpar@1
   101
      return;
alpar@1
   102
}
alpar@1
   103
alpar@1
   104
void npp_deactivate_row(NPP *npp, NPPROW *row)
alpar@1
   105
{     /* make row inactive */
alpar@1
   106
      if (row->temp)
alpar@1
   107
      {  row->temp = 0;
alpar@1
   108
         /* move the row to the end of the row list */
alpar@1
   109
         npp_remove_row(npp, row);
alpar@1
   110
         npp_insert_row(npp, row, 1);
alpar@1
   111
      }
alpar@1
   112
      return;
alpar@1
   113
}
alpar@1
   114
alpar@1
   115
void npp_insert_col(NPP *npp, NPPCOL *col, int where)
alpar@1
   116
{     /* insert column to the column list */
alpar@1
   117
      if (where == 0)
alpar@1
   118
      {  /* insert column to the beginning of the column list */
alpar@1
   119
         col->prev = NULL;
alpar@1
   120
         col->next = npp->c_head;
alpar@1
   121
         if (col->next == NULL)
alpar@1
   122
            npp->c_tail = col;
alpar@1
   123
         else
alpar@1
   124
            col->next->prev = col;
alpar@1
   125
         npp->c_head = col;
alpar@1
   126
      }
alpar@1
   127
      else
alpar@1
   128
      {  /* insert column to the end of the column list */
alpar@1
   129
         col->prev = npp->c_tail;
alpar@1
   130
         col->next = NULL;
alpar@1
   131
         if (col->prev == NULL)
alpar@1
   132
            npp->c_head = col;
alpar@1
   133
         else
alpar@1
   134
            col->prev->next = col;
alpar@1
   135
         npp->c_tail = col;
alpar@1
   136
      }
alpar@1
   137
      return;
alpar@1
   138
}
alpar@1
   139
alpar@1
   140
void npp_remove_col(NPP *npp, NPPCOL *col)
alpar@1
   141
{     /* remove column from the column list */
alpar@1
   142
      if (col->prev == NULL)
alpar@1
   143
         npp->c_head = col->next;
alpar@1
   144
      else
alpar@1
   145
         col->prev->next = col->next;
alpar@1
   146
      if (col->next == NULL)
alpar@1
   147
         npp->c_tail = col->prev;
alpar@1
   148
      else
alpar@1
   149
         col->next->prev = col->prev;
alpar@1
   150
      return;
alpar@1
   151
}
alpar@1
   152
alpar@1
   153
void npp_activate_col(NPP *npp, NPPCOL *col)
alpar@1
   154
{     /* make column active */
alpar@1
   155
      if (!col->temp)
alpar@1
   156
      {  col->temp = 1;
alpar@1
   157
         /* move the column to the beginning of the column list */
alpar@1
   158
         npp_remove_col(npp, col);
alpar@1
   159
         npp_insert_col(npp, col, 0);
alpar@1
   160
      }
alpar@1
   161
      return;
alpar@1
   162
}
alpar@1
   163
alpar@1
   164
void npp_deactivate_col(NPP *npp, NPPCOL *col)
alpar@1
   165
{     /* make column inactive */
alpar@1
   166
      if (col->temp)
alpar@1
   167
      {  col->temp = 0;
alpar@1
   168
         /* move the column to the end of the column list */
alpar@1
   169
         npp_remove_col(npp, col);
alpar@1
   170
         npp_insert_col(npp, col, 1);
alpar@1
   171
      }
alpar@1
   172
      return;
alpar@1
   173
}
alpar@1
   174
alpar@1
   175
NPPROW *npp_add_row(NPP *npp)
alpar@1
   176
{     /* add new row to the current problem */
alpar@1
   177
      NPPROW *row;
alpar@1
   178
      row = dmp_get_atom(npp->pool, sizeof(NPPROW));
alpar@1
   179
      row->i = ++(npp->nrows);
alpar@1
   180
      row->name = NULL;
alpar@1
   181
      row->lb = -DBL_MAX, row->ub = +DBL_MAX;
alpar@1
   182
      row->ptr = NULL;
alpar@1
   183
      row->temp = 0;
alpar@1
   184
      npp_insert_row(npp, row, 1);
alpar@1
   185
      return row;
alpar@1
   186
}
alpar@1
   187
alpar@1
   188
NPPCOL *npp_add_col(NPP *npp)
alpar@1
   189
{     /* add new column to the current problem */
alpar@1
   190
      NPPCOL *col;
alpar@1
   191
      col = dmp_get_atom(npp->pool, sizeof(NPPCOL));
alpar@1
   192
      col->j = ++(npp->ncols);
alpar@1
   193
      col->name = NULL;
alpar@1
   194
#if 0
alpar@1
   195
      col->kind = GLP_CV;
alpar@1
   196
#else
alpar@1
   197
      col->is_int = 0;
alpar@1
   198
#endif
alpar@1
   199
      col->lb = col->ub = col->coef = 0.0;
alpar@1
   200
      col->ptr = NULL;
alpar@1
   201
      col->temp = 0;
alpar@1
   202
      npp_insert_col(npp, col, 1);
alpar@1
   203
      return col;
alpar@1
   204
}
alpar@1
   205
alpar@1
   206
NPPAIJ *npp_add_aij(NPP *npp, NPPROW *row, NPPCOL *col, double val)
alpar@1
   207
{     /* add new element to the constraint matrix */
alpar@1
   208
      NPPAIJ *aij;
alpar@1
   209
      aij = dmp_get_atom(npp->pool, sizeof(NPPAIJ));
alpar@1
   210
      aij->row = row;
alpar@1
   211
      aij->col = col;
alpar@1
   212
      aij->val = val;
alpar@1
   213
      aij->r_prev = NULL;
alpar@1
   214
      aij->r_next = row->ptr;
alpar@1
   215
      aij->c_prev = NULL;
alpar@1
   216
      aij->c_next = col->ptr;
alpar@1
   217
      if (aij->r_next != NULL)
alpar@1
   218
         aij->r_next->r_prev = aij;
alpar@1
   219
      if (aij->c_next != NULL)
alpar@1
   220
         aij->c_next->c_prev = aij;
alpar@1
   221
      row->ptr = col->ptr = aij;
alpar@1
   222
      return aij;
alpar@1
   223
}
alpar@1
   224
alpar@1
   225
int npp_row_nnz(NPP *npp, NPPROW *row)
alpar@1
   226
{     /* count number of non-zero coefficients in row */
alpar@1
   227
      NPPAIJ *aij;
alpar@1
   228
      int nnz;
alpar@1
   229
      xassert(npp == npp);
alpar@1
   230
      nnz = 0;
alpar@1
   231
      for (aij = row->ptr; aij != NULL; aij = aij->r_next)
alpar@1
   232
         nnz++;
alpar@1
   233
      return nnz;
alpar@1
   234
}
alpar@1
   235
alpar@1
   236
int npp_col_nnz(NPP *npp, NPPCOL *col)
alpar@1
   237
{     /* count number of non-zero coefficients in column */
alpar@1
   238
      NPPAIJ *aij;
alpar@1
   239
      int nnz;
alpar@1
   240
      xassert(npp == npp);
alpar@1
   241
      nnz = 0;
alpar@1
   242
      for (aij = col->ptr; aij != NULL; aij = aij->c_next)
alpar@1
   243
         nnz++;
alpar@1
   244
      return nnz;
alpar@1
   245
}
alpar@1
   246
alpar@1
   247
void *npp_push_tse(NPP *npp, int (*func)(NPP *npp, void *info),
alpar@1
   248
      int size)
alpar@1
   249
{     /* push new entry to the transformation stack */
alpar@1
   250
      NPPTSE *tse;
alpar@1
   251
      tse = dmp_get_atom(npp->stack, sizeof(NPPTSE));
alpar@1
   252
      tse->func = func;
alpar@1
   253
      tse->info = dmp_get_atom(npp->stack, size);
alpar@1
   254
      tse->link = npp->top;
alpar@1
   255
      npp->top = tse;
alpar@1
   256
      return tse->info;
alpar@1
   257
}
alpar@1
   258
alpar@1
   259
#if 1 /* 23/XII-2009 */
alpar@1
   260
void npp_erase_row(NPP *npp, NPPROW *row)
alpar@1
   261
{     /* erase row content to make it empty */
alpar@1
   262
      NPPAIJ *aij;
alpar@1
   263
      while (row->ptr != NULL)
alpar@1
   264
      {  aij = row->ptr;
alpar@1
   265
         row->ptr = aij->r_next;
alpar@1
   266
         if (aij->c_prev == NULL)
alpar@1
   267
            aij->col->ptr = aij->c_next;
alpar@1
   268
         else
alpar@1
   269
            aij->c_prev->c_next = aij->c_next;
alpar@1
   270
         if (aij->c_next == NULL)
alpar@1
   271
            ;
alpar@1
   272
         else
alpar@1
   273
            aij->c_next->c_prev = aij->c_prev;
alpar@1
   274
         dmp_free_atom(npp->pool, aij, sizeof(NPPAIJ));
alpar@1
   275
      }
alpar@1
   276
      return;
alpar@1
   277
}
alpar@1
   278
#endif
alpar@1
   279
alpar@1
   280
void npp_del_row(NPP *npp, NPPROW *row)
alpar@1
   281
{     /* remove row from the current problem */
alpar@1
   282
#if 0 /* 23/XII-2009 */
alpar@1
   283
      NPPAIJ *aij;
alpar@1
   284
#endif
alpar@1
   285
      if (row->name != NULL)
alpar@1
   286
         dmp_free_atom(npp->pool, row->name, strlen(row->name)+1);
alpar@1
   287
#if 0 /* 23/XII-2009 */
alpar@1
   288
      while (row->ptr != NULL)
alpar@1
   289
      {  aij = row->ptr;
alpar@1
   290
         row->ptr = aij->r_next;
alpar@1
   291
         if (aij->c_prev == NULL)
alpar@1
   292
            aij->col->ptr = aij->c_next;
alpar@1
   293
         else
alpar@1
   294
            aij->c_prev->c_next = aij->c_next;
alpar@1
   295
         if (aij->c_next == NULL)
alpar@1
   296
            ;
alpar@1
   297
         else
alpar@1
   298
            aij->c_next->c_prev = aij->c_prev;
alpar@1
   299
         dmp_free_atom(npp->pool, aij, sizeof(NPPAIJ));
alpar@1
   300
      }
alpar@1
   301
#else
alpar@1
   302
      npp_erase_row(npp, row);
alpar@1
   303
#endif
alpar@1
   304
      npp_remove_row(npp, row);
alpar@1
   305
      dmp_free_atom(npp->pool, row, sizeof(NPPROW));
alpar@1
   306
      return;
alpar@1
   307
}
alpar@1
   308
alpar@1
   309
void npp_del_col(NPP *npp, NPPCOL *col)
alpar@1
   310
{     /* remove column from the current problem */
alpar@1
   311
      NPPAIJ *aij;
alpar@1
   312
      if (col->name != NULL)
alpar@1
   313
         dmp_free_atom(npp->pool, col->name, strlen(col->name)+1);
alpar@1
   314
      while (col->ptr != NULL)
alpar@1
   315
      {  aij = col->ptr;
alpar@1
   316
         col->ptr = aij->c_next;
alpar@1
   317
         if (aij->r_prev == NULL)
alpar@1
   318
            aij->row->ptr = aij->r_next;
alpar@1
   319
         else
alpar@1
   320
            aij->r_prev->r_next = aij->r_next;
alpar@1
   321
         if (aij->r_next == NULL)
alpar@1
   322
            ;
alpar@1
   323
         else
alpar@1
   324
            aij->r_next->r_prev = aij->r_prev;
alpar@1
   325
         dmp_free_atom(npp->pool, aij, sizeof(NPPAIJ));
alpar@1
   326
      }
alpar@1
   327
      npp_remove_col(npp, col);
alpar@1
   328
      dmp_free_atom(npp->pool, col, sizeof(NPPCOL));
alpar@1
   329
      return;
alpar@1
   330
}
alpar@1
   331
alpar@1
   332
void npp_del_aij(NPP *npp, NPPAIJ *aij)
alpar@1
   333
{     /* remove element from the constraint matrix */
alpar@1
   334
      if (aij->r_prev == NULL)
alpar@1
   335
         aij->row->ptr = aij->r_next;
alpar@1
   336
      else
alpar@1
   337
         aij->r_prev->r_next = aij->r_next;
alpar@1
   338
      if (aij->r_next == NULL)
alpar@1
   339
         ;
alpar@1
   340
      else
alpar@1
   341
         aij->r_next->r_prev = aij->r_prev;
alpar@1
   342
      if (aij->c_prev == NULL)
alpar@1
   343
         aij->col->ptr = aij->c_next;
alpar@1
   344
      else
alpar@1
   345
         aij->c_prev->c_next = aij->c_next;
alpar@1
   346
      if (aij->c_next == NULL)
alpar@1
   347
         ;
alpar@1
   348
      else
alpar@1
   349
         aij->c_next->c_prev = aij->c_prev;
alpar@1
   350
      dmp_free_atom(npp->pool, aij, sizeof(NPPAIJ));
alpar@1
   351
      return;
alpar@1
   352
}
alpar@1
   353
alpar@1
   354
void npp_load_prob(NPP *npp, glp_prob *orig, int names, int sol,
alpar@1
   355
      int scaling)
alpar@1
   356
{     /* load original problem into the preprocessor workspace */
alpar@1
   357
      int m = orig->m;
alpar@1
   358
      int n = orig->n;
alpar@1
   359
      NPPROW **link;
alpar@1
   360
      int i, j;
alpar@1
   361
      double dir;
alpar@1
   362
      xassert(names == GLP_OFF || names == GLP_ON);
alpar@1
   363
      xassert(sol == GLP_SOL || sol == GLP_IPT || sol == GLP_MIP);
alpar@1
   364
      xassert(scaling == GLP_OFF || scaling == GLP_ON);
alpar@1
   365
      if (sol == GLP_MIP) xassert(!scaling);
alpar@1
   366
      npp->orig_dir = orig->dir;
alpar@1
   367
      if (npp->orig_dir == GLP_MIN)
alpar@1
   368
         dir = +1.0;
alpar@1
   369
      else if (npp->orig_dir == GLP_MAX)
alpar@1
   370
         dir = -1.0;
alpar@1
   371
      else
alpar@1
   372
         xassert(npp != npp);
alpar@1
   373
      npp->orig_m = m;
alpar@1
   374
      npp->orig_n = n;
alpar@1
   375
      npp->orig_nnz = orig->nnz;
alpar@1
   376
      if (names && orig->name != NULL)
alpar@1
   377
      {  npp->name = dmp_get_atom(npp->pool, strlen(orig->name)+1);
alpar@1
   378
         strcpy(npp->name, orig->name);
alpar@1
   379
      }
alpar@1
   380
      if (names && orig->obj != NULL)
alpar@1
   381
      {  npp->obj = dmp_get_atom(npp->pool, strlen(orig->obj)+1);
alpar@1
   382
         strcpy(npp->obj, orig->obj);
alpar@1
   383
      }
alpar@1
   384
      npp->c0 = dir * orig->c0;
alpar@1
   385
      /* load rows */
alpar@1
   386
      link = xcalloc(1+m, sizeof(NPPROW *));
alpar@1
   387
      for (i = 1; i <= m; i++)
alpar@1
   388
      {  GLPROW *rrr = orig->row[i];
alpar@1
   389
         NPPROW *row;
alpar@1
   390
         link[i] = row = npp_add_row(npp);
alpar@1
   391
         xassert(row->i == i);
alpar@1
   392
         if (names && rrr->name != NULL)
alpar@1
   393
         {  row->name = dmp_get_atom(npp->pool, strlen(rrr->name)+1);
alpar@1
   394
            strcpy(row->name, rrr->name);
alpar@1
   395
         }
alpar@1
   396
         if (!scaling)
alpar@1
   397
         {  if (rrr->type == GLP_FR)
alpar@1
   398
               row->lb = -DBL_MAX, row->ub = +DBL_MAX;
alpar@1
   399
            else if (rrr->type == GLP_LO)
alpar@1
   400
               row->lb = rrr->lb, row->ub = +DBL_MAX;
alpar@1
   401
            else if (rrr->type == GLP_UP)
alpar@1
   402
               row->lb = -DBL_MAX, row->ub = rrr->ub;
alpar@1
   403
            else if (rrr->type == GLP_DB)
alpar@1
   404
               row->lb = rrr->lb, row->ub = rrr->ub;
alpar@1
   405
            else if (rrr->type == GLP_FX)
alpar@1
   406
               row->lb = row->ub = rrr->lb;
alpar@1
   407
            else
alpar@1
   408
               xassert(rrr != rrr);
alpar@1
   409
         }
alpar@1
   410
         else
alpar@1
   411
         {  double rii = rrr->rii;
alpar@1
   412
            if (rrr->type == GLP_FR)
alpar@1
   413
               row->lb = -DBL_MAX, row->ub = +DBL_MAX;
alpar@1
   414
            else if (rrr->type == GLP_LO)
alpar@1
   415
               row->lb = rrr->lb * rii, row->ub = +DBL_MAX;
alpar@1
   416
            else if (rrr->type == GLP_UP)
alpar@1
   417
               row->lb = -DBL_MAX, row->ub = rrr->ub * rii;
alpar@1
   418
            else if (rrr->type == GLP_DB)
alpar@1
   419
               row->lb = rrr->lb * rii, row->ub = rrr->ub * rii;
alpar@1
   420
            else if (rrr->type == GLP_FX)
alpar@1
   421
               row->lb = row->ub = rrr->lb * rii;
alpar@1
   422
            else
alpar@1
   423
               xassert(rrr != rrr);
alpar@1
   424
         }
alpar@1
   425
      }
alpar@1
   426
      /* load columns and constraint coefficients */
alpar@1
   427
      for (j = 1; j <= n; j++)
alpar@1
   428
      {  GLPCOL *ccc = orig->col[j];
alpar@1
   429
         GLPAIJ *aaa;
alpar@1
   430
         NPPCOL *col;
alpar@1
   431
         col = npp_add_col(npp);
alpar@1
   432
         xassert(col->j == j);
alpar@1
   433
         if (names && ccc->name != NULL)
alpar@1
   434
         {  col->name = dmp_get_atom(npp->pool, strlen(ccc->name)+1);
alpar@1
   435
            strcpy(col->name, ccc->name);
alpar@1
   436
         }
alpar@1
   437
         if (sol == GLP_MIP)
alpar@1
   438
#if 0
alpar@1
   439
            col->kind = ccc->kind;
alpar@1
   440
#else
alpar@1
   441
            col->is_int = (char)(ccc->kind == GLP_IV);
alpar@1
   442
#endif
alpar@1
   443
         if (!scaling)
alpar@1
   444
         {  if (ccc->type == GLP_FR)
alpar@1
   445
               col->lb = -DBL_MAX, col->ub = +DBL_MAX;
alpar@1
   446
            else if (ccc->type == GLP_LO)
alpar@1
   447
               col->lb = ccc->lb, col->ub = +DBL_MAX;
alpar@1
   448
            else if (ccc->type == GLP_UP)
alpar@1
   449
               col->lb = -DBL_MAX, col->ub = ccc->ub;
alpar@1
   450
            else if (ccc->type == GLP_DB)
alpar@1
   451
               col->lb = ccc->lb, col->ub = ccc->ub;
alpar@1
   452
            else if (ccc->type == GLP_FX)
alpar@1
   453
               col->lb = col->ub = ccc->lb;
alpar@1
   454
            else
alpar@1
   455
               xassert(ccc != ccc);
alpar@1
   456
            col->coef = dir * ccc->coef;
alpar@1
   457
            for (aaa = ccc->ptr; aaa != NULL; aaa = aaa->c_next)
alpar@1
   458
               npp_add_aij(npp, link[aaa->row->i], col, aaa->val);
alpar@1
   459
         }
alpar@1
   460
         else
alpar@1
   461
         {  double sjj = ccc->sjj;
alpar@1
   462
            if (ccc->type == GLP_FR)
alpar@1
   463
               col->lb = -DBL_MAX, col->ub = +DBL_MAX;
alpar@1
   464
            else if (ccc->type == GLP_LO)
alpar@1
   465
               col->lb = ccc->lb / sjj, col->ub = +DBL_MAX;
alpar@1
   466
            else if (ccc->type == GLP_UP)
alpar@1
   467
               col->lb = -DBL_MAX, col->ub = ccc->ub / sjj;
alpar@1
   468
            else if (ccc->type == GLP_DB)
alpar@1
   469
               col->lb = ccc->lb / sjj, col->ub = ccc->ub / sjj;
alpar@1
   470
            else if (ccc->type == GLP_FX)
alpar@1
   471
               col->lb = col->ub = ccc->lb / sjj;
alpar@1
   472
            else
alpar@1
   473
               xassert(ccc != ccc);
alpar@1
   474
            col->coef = dir * ccc->coef * sjj;
alpar@1
   475
            for (aaa = ccc->ptr; aaa != NULL; aaa = aaa->c_next)
alpar@1
   476
               npp_add_aij(npp, link[aaa->row->i], col,
alpar@1
   477
                  aaa->row->rii * aaa->val * sjj);
alpar@1
   478
         }
alpar@1
   479
      }
alpar@1
   480
      xfree(link);
alpar@1
   481
      /* keep solution indicator and scaling option */
alpar@1
   482
      npp->sol = sol;
alpar@1
   483
      npp->scaling = scaling;
alpar@1
   484
      return;
alpar@1
   485
}
alpar@1
   486
alpar@1
   487
void npp_build_prob(NPP *npp, glp_prob *prob)
alpar@1
   488
{     /* build resultant (preprocessed) problem */
alpar@1
   489
      NPPROW *row;
alpar@1
   490
      NPPCOL *col;
alpar@1
   491
      NPPAIJ *aij;
alpar@1
   492
      int i, j, type, len, *ind;
alpar@1
   493
      double dir, *val;
alpar@1
   494
      glp_erase_prob(prob);
alpar@1
   495
      glp_set_prob_name(prob, npp->name);
alpar@1
   496
      glp_set_obj_name(prob, npp->obj);
alpar@1
   497
      glp_set_obj_dir(prob, npp->orig_dir);
alpar@1
   498
      if (npp->orig_dir == GLP_MIN)
alpar@1
   499
         dir = +1.0;
alpar@1
   500
      else if (npp->orig_dir == GLP_MAX)
alpar@1
   501
         dir = -1.0;
alpar@1
   502
      else
alpar@1
   503
         xassert(npp != npp);
alpar@1
   504
      glp_set_obj_coef(prob, 0, dir * npp->c0);
alpar@1
   505
      /* build rows */
alpar@1
   506
      for (row = npp->r_head; row != NULL; row = row->next)
alpar@1
   507
      {  row->temp = i = glp_add_rows(prob, 1);
alpar@1
   508
         glp_set_row_name(prob, i, row->name);
alpar@1
   509
         if (row->lb == -DBL_MAX && row->ub == +DBL_MAX)
alpar@1
   510
            type = GLP_FR;
alpar@1
   511
         else if (row->ub == +DBL_MAX)
alpar@1
   512
            type = GLP_LO;
alpar@1
   513
         else if (row->lb == -DBL_MAX)
alpar@1
   514
            type = GLP_UP;
alpar@1
   515
         else if (row->lb != row->ub)
alpar@1
   516
            type = GLP_DB;
alpar@1
   517
         else
alpar@1
   518
            type = GLP_FX;
alpar@1
   519
         glp_set_row_bnds(prob, i, type, row->lb, row->ub);
alpar@1
   520
      }
alpar@1
   521
      /* build columns and the constraint matrix */
alpar@1
   522
      ind = xcalloc(1+prob->m, sizeof(int));
alpar@1
   523
      val = xcalloc(1+prob->m, sizeof(double));
alpar@1
   524
      for (col = npp->c_head; col != NULL; col = col->next)
alpar@1
   525
      {  j = glp_add_cols(prob, 1);
alpar@1
   526
         glp_set_col_name(prob, j, col->name);
alpar@1
   527
#if 0
alpar@1
   528
         glp_set_col_kind(prob, j, col->kind);
alpar@1
   529
#else
alpar@1
   530
         glp_set_col_kind(prob, j, col->is_int ? GLP_IV : GLP_CV);
alpar@1
   531
#endif
alpar@1
   532
         if (col->lb == -DBL_MAX && col->ub == +DBL_MAX)
alpar@1
   533
            type = GLP_FR;
alpar@1
   534
         else if (col->ub == +DBL_MAX)
alpar@1
   535
            type = GLP_LO;
alpar@1
   536
         else if (col->lb == -DBL_MAX)
alpar@1
   537
            type = GLP_UP;
alpar@1
   538
         else if (col->lb != col->ub)
alpar@1
   539
            type = GLP_DB;
alpar@1
   540
         else
alpar@1
   541
            type = GLP_FX;
alpar@1
   542
         glp_set_col_bnds(prob, j, type, col->lb, col->ub);
alpar@1
   543
         glp_set_obj_coef(prob, j, dir * col->coef);
alpar@1
   544
         len = 0;
alpar@1
   545
         for (aij = col->ptr; aij != NULL; aij = aij->c_next)
alpar@1
   546
         {  len++;
alpar@1
   547
            ind[len] = aij->row->temp;
alpar@1
   548
            val[len] = aij->val;
alpar@1
   549
         }
alpar@1
   550
         glp_set_mat_col(prob, j, len, ind, val);
alpar@1
   551
      }
alpar@1
   552
      xfree(ind);
alpar@1
   553
      xfree(val);
alpar@1
   554
      /* resultant problem has been built */
alpar@1
   555
      npp->m = prob->m;
alpar@1
   556
      npp->n = prob->n;
alpar@1
   557
      npp->nnz = prob->nnz;
alpar@1
   558
      npp->row_ref = xcalloc(1+npp->m, sizeof(int));
alpar@1
   559
      npp->col_ref = xcalloc(1+npp->n, sizeof(int));
alpar@1
   560
      for (row = npp->r_head, i = 0; row != NULL; row = row->next)
alpar@1
   561
         npp->row_ref[++i] = row->i;
alpar@1
   562
      for (col = npp->c_head, j = 0; col != NULL; col = col->next)
alpar@1
   563
         npp->col_ref[++j] = col->j;
alpar@1
   564
      /* transformed problem segment is no longer needed */
alpar@1
   565
      dmp_delete_pool(npp->pool), npp->pool = NULL;
alpar@1
   566
      npp->name = npp->obj = NULL;
alpar@1
   567
      npp->c0 = 0.0;
alpar@1
   568
      npp->r_head = npp->r_tail = NULL;
alpar@1
   569
      npp->c_head = npp->c_tail = NULL;
alpar@1
   570
      return;
alpar@1
   571
}
alpar@1
   572
alpar@1
   573
void npp_postprocess(NPP *npp, glp_prob *prob)
alpar@1
   574
{     /* postprocess solution from the resultant problem */
alpar@1
   575
      GLPROW *row;
alpar@1
   576
      GLPCOL *col;
alpar@1
   577
      NPPTSE *tse;
alpar@1
   578
      int i, j, k;
alpar@1
   579
      double dir;
alpar@1
   580
      xassert(npp->orig_dir == prob->dir);
alpar@1
   581
      if (npp->orig_dir == GLP_MIN)
alpar@1
   582
         dir = +1.0;
alpar@1
   583
      else if (npp->orig_dir == GLP_MAX)
alpar@1
   584
         dir = -1.0;
alpar@1
   585
      else
alpar@1
   586
         xassert(npp != npp);
alpar@1
   587
      xassert(npp->m == prob->m);
alpar@1
   588
      xassert(npp->n == prob->n);
alpar@1
   589
      xassert(npp->nnz == prob->nnz);
alpar@1
   590
      /* copy solution status */
alpar@1
   591
      if (npp->sol == GLP_SOL)
alpar@1
   592
      {  npp->p_stat = prob->pbs_stat;
alpar@1
   593
         npp->d_stat = prob->dbs_stat;
alpar@1
   594
      }
alpar@1
   595
      else if (npp->sol == GLP_IPT)
alpar@1
   596
         npp->t_stat = prob->ipt_stat;
alpar@1
   597
      else if (npp->sol == GLP_MIP)
alpar@1
   598
         npp->i_stat = prob->mip_stat;
alpar@1
   599
      else
alpar@1
   600
         xassert(npp != npp);
alpar@1
   601
      /* allocate solution arrays */
alpar@1
   602
      if (npp->sol == GLP_SOL)
alpar@1
   603
      {  if (npp->r_stat == NULL)
alpar@1
   604
            npp->r_stat = xcalloc(1+npp->nrows, sizeof(char));
alpar@1
   605
         for (i = 1; i <= npp->nrows; i++)
alpar@1
   606
            npp->r_stat[i] = 0;
alpar@1
   607
         if (npp->c_stat == NULL)
alpar@1
   608
            npp->c_stat = xcalloc(1+npp->ncols, sizeof(char));
alpar@1
   609
         for (j = 1; j <= npp->ncols; j++)
alpar@1
   610
            npp->c_stat[j] = 0;
alpar@1
   611
      }
alpar@1
   612
#if 0
alpar@1
   613
      if (npp->r_prim == NULL)
alpar@1
   614
         npp->r_prim = xcalloc(1+npp->nrows, sizeof(double));
alpar@1
   615
      for (i = 1; i <= npp->nrows; i++)
alpar@1
   616
         npp->r_prim[i] = DBL_MAX;
alpar@1
   617
#endif
alpar@1
   618
      if (npp->c_value == NULL)
alpar@1
   619
         npp->c_value = xcalloc(1+npp->ncols, sizeof(double));
alpar@1
   620
      for (j = 1; j <= npp->ncols; j++)
alpar@1
   621
         npp->c_value[j] = DBL_MAX;
alpar@1
   622
      if (npp->sol != GLP_MIP)
alpar@1
   623
      {  if (npp->r_pi == NULL)
alpar@1
   624
            npp->r_pi = xcalloc(1+npp->nrows, sizeof(double));
alpar@1
   625
         for (i = 1; i <= npp->nrows; i++)
alpar@1
   626
            npp->r_pi[i] = DBL_MAX;
alpar@1
   627
#if 0
alpar@1
   628
         if (npp->c_dual == NULL)
alpar@1
   629
            npp->c_dual = xcalloc(1+npp->ncols, sizeof(double));
alpar@1
   630
         for (j = 1; j <= npp->ncols; j++)
alpar@1
   631
            npp->c_dual[j] = DBL_MAX;
alpar@1
   632
#endif
alpar@1
   633
      }
alpar@1
   634
      /* copy solution components from the resultant problem */
alpar@1
   635
      if (npp->sol == GLP_SOL)
alpar@1
   636
      {  for (i = 1; i <= npp->m; i++)
alpar@1
   637
         {  row = prob->row[i];
alpar@1
   638
            k = npp->row_ref[i];
alpar@1
   639
            npp->r_stat[k] = (char)row->stat;
alpar@1
   640
            /*npp->r_prim[k] = row->prim;*/
alpar@1
   641
            npp->r_pi[k] = dir * row->dual;
alpar@1
   642
         }
alpar@1
   643
         for (j = 1; j <= npp->n; j++)
alpar@1
   644
         {  col = prob->col[j];
alpar@1
   645
            k = npp->col_ref[j];
alpar@1
   646
            npp->c_stat[k] = (char)col->stat;
alpar@1
   647
            npp->c_value[k] = col->prim;
alpar@1
   648
            /*npp->c_dual[k] = dir * col->dual;*/
alpar@1
   649
         }
alpar@1
   650
      }
alpar@1
   651
      else if (npp->sol == GLP_IPT)
alpar@1
   652
      {  for (i = 1; i <= npp->m; i++)
alpar@1
   653
         {  row = prob->row[i];
alpar@1
   654
            k = npp->row_ref[i];
alpar@1
   655
            /*npp->r_prim[k] = row->pval;*/
alpar@1
   656
            npp->r_pi[k] = dir * row->dval;
alpar@1
   657
         }
alpar@1
   658
         for (j = 1; j <= npp->n; j++)
alpar@1
   659
         {  col = prob->col[j];
alpar@1
   660
            k = npp->col_ref[j];
alpar@1
   661
            npp->c_value[k] = col->pval;
alpar@1
   662
            /*npp->c_dual[k] = dir * col->dval;*/
alpar@1
   663
         }
alpar@1
   664
      }
alpar@1
   665
      else if (npp->sol == GLP_MIP)
alpar@1
   666
      {
alpar@1
   667
#if 0
alpar@1
   668
         for (i = 1; i <= npp->m; i++)
alpar@1
   669
         {  row = prob->row[i];
alpar@1
   670
            k = npp->row_ref[i];
alpar@1
   671
            /*npp->r_prim[k] = row->mipx;*/
alpar@1
   672
         }
alpar@1
   673
#endif
alpar@1
   674
         for (j = 1; j <= npp->n; j++)
alpar@1
   675
         {  col = prob->col[j];
alpar@1
   676
            k = npp->col_ref[j];
alpar@1
   677
            npp->c_value[k] = col->mipx;
alpar@1
   678
         }
alpar@1
   679
      }
alpar@1
   680
      else
alpar@1
   681
         xassert(npp != npp);
alpar@1
   682
      /* perform postprocessing to construct solution to the original
alpar@1
   683
         problem */
alpar@1
   684
      for (tse = npp->top; tse != NULL; tse = tse->link)
alpar@1
   685
      {  xassert(tse->func != NULL);
alpar@1
   686
         xassert(tse->func(npp, tse->info) == 0);
alpar@1
   687
      }
alpar@1
   688
      return;
alpar@1
   689
}
alpar@1
   690
alpar@1
   691
void npp_unload_sol(NPP *npp, glp_prob *orig)
alpar@1
   692
{     /* store solution to the original problem */
alpar@1
   693
      GLPROW *row;
alpar@1
   694
      GLPCOL *col;
alpar@1
   695
      int i, j;
alpar@1
   696
      double dir;
alpar@1
   697
      xassert(npp->orig_dir == orig->dir);
alpar@1
   698
      if (npp->orig_dir == GLP_MIN)
alpar@1
   699
         dir = +1.0;
alpar@1
   700
      else if (npp->orig_dir == GLP_MAX)
alpar@1
   701
         dir = -1.0;
alpar@1
   702
      else
alpar@1
   703
         xassert(npp != npp);
alpar@1
   704
      xassert(npp->orig_m == orig->m);
alpar@1
   705
      xassert(npp->orig_n == orig->n);
alpar@1
   706
      xassert(npp->orig_nnz == orig->nnz);
alpar@1
   707
      if (npp->sol == GLP_SOL)
alpar@1
   708
      {  /* store basic solution */
alpar@1
   709
         orig->valid = 0;
alpar@1
   710
         orig->pbs_stat = npp->p_stat;
alpar@1
   711
         orig->dbs_stat = npp->d_stat;
alpar@1
   712
         orig->obj_val = orig->c0;
alpar@1
   713
         orig->some = 0;
alpar@1
   714
         for (i = 1; i <= orig->m; i++)
alpar@1
   715
         {  row = orig->row[i];
alpar@1
   716
            row->stat = npp->r_stat[i];
alpar@1
   717
            if (!npp->scaling)
alpar@1
   718
            {  /*row->prim = npp->r_prim[i];*/
alpar@1
   719
               row->dual = dir * npp->r_pi[i];
alpar@1
   720
            }
alpar@1
   721
            else
alpar@1
   722
            {  /*row->prim = npp->r_prim[i] / row->rii;*/
alpar@1
   723
               row->dual = dir * npp->r_pi[i] * row->rii;
alpar@1
   724
            }
alpar@1
   725
            if (row->stat == GLP_BS)
alpar@1
   726
               row->dual = 0.0;
alpar@1
   727
            else if (row->stat == GLP_NL)
alpar@1
   728
            {  xassert(row->type == GLP_LO || row->type == GLP_DB);
alpar@1
   729
               row->prim = row->lb;
alpar@1
   730
            }
alpar@1
   731
            else if (row->stat == GLP_NU)
alpar@1
   732
            {  xassert(row->type == GLP_UP || row->type == GLP_DB);
alpar@1
   733
               row->prim = row->ub;
alpar@1
   734
            }
alpar@1
   735
            else if (row->stat == GLP_NF)
alpar@1
   736
            {  xassert(row->type == GLP_FR);
alpar@1
   737
               row->prim = 0.0;
alpar@1
   738
            }
alpar@1
   739
            else if (row->stat == GLP_NS)
alpar@1
   740
            {  xassert(row->type == GLP_FX);
alpar@1
   741
               row->prim = row->lb;
alpar@1
   742
            }
alpar@1
   743
            else
alpar@1
   744
               xassert(row != row);
alpar@1
   745
         }
alpar@1
   746
         for (j = 1; j <= orig->n; j++)
alpar@1
   747
         {  col = orig->col[j];
alpar@1
   748
            col->stat = npp->c_stat[j];
alpar@1
   749
            if (!npp->scaling)
alpar@1
   750
            {  col->prim = npp->c_value[j];
alpar@1
   751
               /*col->dual = dir * npp->c_dual[j];*/
alpar@1
   752
            }
alpar@1
   753
            else
alpar@1
   754
            {  col->prim = npp->c_value[j] * col->sjj;
alpar@1
   755
               /*col->dual = dir * npp->c_dual[j] / col->sjj;*/
alpar@1
   756
            }
alpar@1
   757
            if (col->stat == GLP_BS)
alpar@1
   758
               col->dual = 0.0;
alpar@1
   759
#if 1
alpar@1
   760
            else if (col->stat == GLP_NL)
alpar@1
   761
            {  xassert(col->type == GLP_LO || col->type == GLP_DB);
alpar@1
   762
               col->prim = col->lb;
alpar@1
   763
            }
alpar@1
   764
            else if (col->stat == GLP_NU)
alpar@1
   765
            {  xassert(col->type == GLP_UP || col->type == GLP_DB);
alpar@1
   766
               col->prim = col->ub;
alpar@1
   767
            }
alpar@1
   768
            else if (col->stat == GLP_NF)
alpar@1
   769
            {  xassert(col->type == GLP_FR);
alpar@1
   770
               col->prim = 0.0;
alpar@1
   771
            }
alpar@1
   772
            else if (col->stat == GLP_NS)
alpar@1
   773
            {  xassert(col->type == GLP_FX);
alpar@1
   774
               col->prim = col->lb;
alpar@1
   775
            }
alpar@1
   776
            else
alpar@1
   777
               xassert(col != col);
alpar@1
   778
#endif
alpar@1
   779
            orig->obj_val += col->coef * col->prim;
alpar@1
   780
         }
alpar@1
   781
#if 1
alpar@1
   782
         /* compute primal values of inactive rows */
alpar@1
   783
         for (i = 1; i <= orig->m; i++)
alpar@1
   784
         {  row = orig->row[i];
alpar@1
   785
            if (row->stat == GLP_BS)
alpar@1
   786
            {  GLPAIJ *aij;
alpar@1
   787
               double temp;
alpar@1
   788
               temp = 0.0;
alpar@1
   789
               for (aij = row->ptr; aij != NULL; aij = aij->r_next)
alpar@1
   790
                  temp += aij->val * aij->col->prim;
alpar@1
   791
               row->prim = temp;
alpar@1
   792
            }
alpar@1
   793
         }
alpar@1
   794
         /* compute reduced costs of active columns */
alpar@1
   795
         for (j = 1; j <= orig->n; j++)
alpar@1
   796
         {  col = orig->col[j];
alpar@1
   797
            if (col->stat != GLP_BS)
alpar@1
   798
            {  GLPAIJ *aij;
alpar@1
   799
               double temp;
alpar@1
   800
               temp = col->coef;
alpar@1
   801
               for (aij = col->ptr; aij != NULL; aij = aij->c_next)
alpar@1
   802
                  temp -= aij->val * aij->row->dual;
alpar@1
   803
               col->dual = temp;
alpar@1
   804
            }
alpar@1
   805
         }
alpar@1
   806
#endif
alpar@1
   807
      }
alpar@1
   808
      else if (npp->sol == GLP_IPT)
alpar@1
   809
      {  /* store interior-point solution */
alpar@1
   810
         orig->ipt_stat = npp->t_stat;
alpar@1
   811
         orig->ipt_obj = orig->c0;
alpar@1
   812
         for (i = 1; i <= orig->m; i++)
alpar@1
   813
         {  row = orig->row[i];
alpar@1
   814
            if (!npp->scaling)
alpar@1
   815
            {  /*row->pval = npp->r_prim[i];*/
alpar@1
   816
               row->dval = dir * npp->r_pi[i];
alpar@1
   817
            }
alpar@1
   818
            else
alpar@1
   819
            {  /*row->pval = npp->r_prim[i] / row->rii;*/
alpar@1
   820
               row->dval = dir * npp->r_pi[i] * row->rii;
alpar@1
   821
            }
alpar@1
   822
         }
alpar@1
   823
         for (j = 1; j <= orig->n; j++)
alpar@1
   824
         {  col = orig->col[j];
alpar@1
   825
            if (!npp->scaling)
alpar@1
   826
            {  col->pval = npp->c_value[j];
alpar@1
   827
               /*col->dval = dir * npp->c_dual[j];*/
alpar@1
   828
            }
alpar@1
   829
            else
alpar@1
   830
            {  col->pval = npp->c_value[j] * col->sjj;
alpar@1
   831
               /*col->dval = dir * npp->c_dual[j] / col->sjj;*/
alpar@1
   832
            }
alpar@1
   833
            orig->ipt_obj += col->coef * col->pval;
alpar@1
   834
         }
alpar@1
   835
#if 1
alpar@1
   836
         /* compute row primal values */
alpar@1
   837
         for (i = 1; i <= orig->m; i++)
alpar@1
   838
         {  row = orig->row[i];
alpar@1
   839
            {  GLPAIJ *aij;
alpar@1
   840
               double temp;
alpar@1
   841
               temp = 0.0;
alpar@1
   842
               for (aij = row->ptr; aij != NULL; aij = aij->r_next)
alpar@1
   843
                  temp += aij->val * aij->col->pval;
alpar@1
   844
               row->pval = temp;
alpar@1
   845
            }
alpar@1
   846
         }
alpar@1
   847
         /* compute column dual values */
alpar@1
   848
         for (j = 1; j <= orig->n; j++)
alpar@1
   849
         {  col = orig->col[j];
alpar@1
   850
            {  GLPAIJ *aij;
alpar@1
   851
               double temp;
alpar@1
   852
               temp = col->coef;
alpar@1
   853
               for (aij = col->ptr; aij != NULL; aij = aij->c_next)
alpar@1
   854
                  temp -= aij->val * aij->row->dval;
alpar@1
   855
               col->dval = temp;
alpar@1
   856
            }
alpar@1
   857
         }
alpar@1
   858
#endif
alpar@1
   859
      }
alpar@1
   860
      else if (npp->sol == GLP_MIP)
alpar@1
   861
      {  /* store MIP solution */
alpar@1
   862
         xassert(!npp->scaling);
alpar@1
   863
         orig->mip_stat = npp->i_stat;
alpar@1
   864
         orig->mip_obj = orig->c0;
alpar@1
   865
#if 0
alpar@1
   866
         for (i = 1; i <= orig->m; i++)
alpar@1
   867
         {  row = orig->row[i];
alpar@1
   868
            /*row->mipx = npp->r_prim[i];*/
alpar@1
   869
         }
alpar@1
   870
#endif
alpar@1
   871
         for (j = 1; j <= orig->n; j++)
alpar@1
   872
         {  col = orig->col[j];
alpar@1
   873
            col->mipx = npp->c_value[j];
alpar@1
   874
            if (col->kind == GLP_IV)
alpar@1
   875
               xassert(col->mipx == floor(col->mipx));
alpar@1
   876
            orig->mip_obj += col->coef * col->mipx;
alpar@1
   877
         }
alpar@1
   878
#if 1
alpar@1
   879
         /* compute row primal values */
alpar@1
   880
         for (i = 1; i <= orig->m; i++)
alpar@1
   881
         {  row = orig->row[i];
alpar@1
   882
            {  GLPAIJ *aij;
alpar@1
   883
               double temp;
alpar@1
   884
               temp = 0.0;
alpar@1
   885
               for (aij = row->ptr; aij != NULL; aij = aij->r_next)
alpar@1
   886
                  temp += aij->val * aij->col->mipx;
alpar@1
   887
               row->mipx = temp;
alpar@1
   888
            }
alpar@1
   889
         }
alpar@1
   890
#endif
alpar@1
   891
      }
alpar@1
   892
      else
alpar@1
   893
         xassert(npp != npp);
alpar@1
   894
      return;
alpar@1
   895
}
alpar@1
   896
alpar@1
   897
void npp_delete_wksp(NPP *npp)
alpar@1
   898
{     /* delete LP/MIP preprocessor workspace */
alpar@1
   899
      if (npp->pool != NULL)
alpar@1
   900
         dmp_delete_pool(npp->pool);
alpar@1
   901
      if (npp->stack != NULL)
alpar@1
   902
         dmp_delete_pool(npp->stack);
alpar@1
   903
      if (npp->row_ref != NULL)
alpar@1
   904
         xfree(npp->row_ref);
alpar@1
   905
      if (npp->col_ref != NULL)
alpar@1
   906
         xfree(npp->col_ref);
alpar@1
   907
      if (npp->r_stat != NULL)
alpar@1
   908
         xfree(npp->r_stat);
alpar@1
   909
#if 0
alpar@1
   910
      if (npp->r_prim != NULL)
alpar@1
   911
         xfree(npp->r_prim);
alpar@1
   912
#endif
alpar@1
   913
      if (npp->r_pi != NULL)
alpar@1
   914
         xfree(npp->r_pi);
alpar@1
   915
      if (npp->c_stat != NULL)
alpar@1
   916
         xfree(npp->c_stat);
alpar@1
   917
      if (npp->c_value != NULL)
alpar@1
   918
         xfree(npp->c_value);
alpar@1
   919
#if 0
alpar@1
   920
      if (npp->c_dual != NULL)
alpar@1
   921
         xfree(npp->c_dual);
alpar@1
   922
#endif
alpar@1
   923
      xfree(npp);
alpar@1
   924
      return;
alpar@1
   925
}
alpar@1
   926
alpar@1
   927
/* eof */