glpapi04.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* glpapi04.c (problem scaling routines) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #include "glpapi.h"
  24. /***********************************************************************
  25. * NAME
  26. *
  27. * glp_set_rii - set (change) row scale factor
  28. *
  29. * SYNOPSIS
  30. *
  31. * void glp_set_rii(glp_prob *lp, int i, double rii);
  32. *
  33. * DESCRIPTION
  34. *
  35. * The routine glp_set_rii sets (changes) the scale factor r[i,i] for
  36. * i-th row of the specified problem object. */
  37. void glp_set_rii(glp_prob *lp, int i, double rii)
  38. { if (!(1 <= i && i <= lp->m))
  39. xerror("glp_set_rii: i = %d; row number out of range\n", i);
  40. if (rii <= 0.0)
  41. xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
  42. i, rii);
  43. if (lp->valid && lp->row[i]->rii != rii)
  44. { GLPAIJ *aij;
  45. for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
  46. { if (aij->col->stat == GLP_BS)
  47. { /* invalidate the basis factorization */
  48. lp->valid = 0;
  49. break;
  50. }
  51. }
  52. }
  53. lp->row[i]->rii = rii;
  54. return;
  55. }
  56. /***********************************************************************
  57. * NAME
  58. *
  59. * glp_set sjj - set (change) column scale factor
  60. *
  61. * SYNOPSIS
  62. *
  63. * void glp_set_sjj(glp_prob *lp, int j, double sjj);
  64. *
  65. * DESCRIPTION
  66. *
  67. * The routine glp_set_sjj sets (changes) the scale factor s[j,j] for
  68. * j-th column of the specified problem object. */
  69. void glp_set_sjj(glp_prob *lp, int j, double sjj)
  70. { if (!(1 <= j && j <= lp->n))
  71. xerror("glp_set_sjj: j = %d; column number out of range\n", j);
  72. if (sjj <= 0.0)
  73. xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
  74. j, sjj);
  75. if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
  76. GLP_BS)
  77. { /* invalidate the basis factorization */
  78. lp->valid = 0;
  79. }
  80. lp->col[j]->sjj = sjj;
  81. return;
  82. }
  83. /***********************************************************************
  84. * NAME
  85. *
  86. * glp_get_rii - retrieve row scale factor
  87. *
  88. * SYNOPSIS
  89. *
  90. * double glp_get_rii(glp_prob *lp, int i);
  91. *
  92. * RETURNS
  93. *
  94. * The routine glp_get_rii returns current scale factor r[i,i] for i-th
  95. * row of the specified problem object. */
  96. double glp_get_rii(glp_prob *lp, int i)
  97. { if (!(1 <= i && i <= lp->m))
  98. xerror("glp_get_rii: i = %d; row number out of range\n", i);
  99. return lp->row[i]->rii;
  100. }
  101. /***********************************************************************
  102. * NAME
  103. *
  104. * glp_get_sjj - retrieve column scale factor
  105. *
  106. * SYNOPSIS
  107. *
  108. * double glp_get_sjj(glp_prob *lp, int j);
  109. *
  110. * RETURNS
  111. *
  112. * The routine glp_get_sjj returns current scale factor s[j,j] for j-th
  113. * column of the specified problem object. */
  114. double glp_get_sjj(glp_prob *lp, int j)
  115. { if (!(1 <= j && j <= lp->n))
  116. xerror("glp_get_sjj: j = %d; column number out of range\n", j);
  117. return lp->col[j]->sjj;
  118. }
  119. /***********************************************************************
  120. * NAME
  121. *
  122. * glp_unscale_prob - unscale problem data
  123. *
  124. * SYNOPSIS
  125. *
  126. * void glp_unscale_prob(glp_prob *lp);
  127. *
  128. * DESCRIPTION
  129. *
  130. * The routine glp_unscale_prob performs unscaling of problem data for
  131. * the specified problem object.
  132. *
  133. * "Unscaling" means replacing the current scaling matrices R and S by
  134. * unity matrices that cancels the scaling effect. */
  135. void glp_unscale_prob(glp_prob *lp)
  136. { int m = glp_get_num_rows(lp);
  137. int n = glp_get_num_cols(lp);
  138. int i, j;
  139. for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0);
  140. for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0);
  141. return;
  142. }
  143. /* eof */