1
2
3 /* Routines located in lp_BFP2.cpp; optional shared for canned implementations */
4 /* Cfr. lp_BFP.h for definitions */
5 /* ---------------------------------------------------------------------------------- */
6
7
8 /* DON'T MODIFY */
bfp_init(lprec * lp,int size,int delta,char * options)9 MYBOOL BFP_CALLMODEL bfp_init(lprec *lp, int size, int delta, char *options)
10 {
11 INVrec *lu;
12
13 lp->invB = (INVrec *) calloc(1, sizeof(*(lp->invB)));
14 lu = lp->invB;
15 if((lu == NULL) ||
16 !lp->bfp_resize(lp, size) ||
17 !lp->bfp_restart(lp))
18 return( FALSE );
19
20 /* Store any passed options */
21 if(options != NULL) {
22 size_t len = strlen(options);
23 lu->opts = (char *) malloc(len + 1);
24 strcpy(lu->opts, options);
25 }
26
27 /* Prepare for factorization and undo values reset by bfp_preparefactorization */
28 lp->bfp_preparefactorization(lp);
29 lu->num_refact = 0;
30
31 return( TRUE );
32 }
33
34 /* DON'T MODIFY */
bfp_restart(lprec * lp)35 MYBOOL BFP_CALLMODEL bfp_restart(lprec *lp)
36 {
37 INVrec *lu;
38
39 lu = lp->invB;
40 if(lu == NULL)
41 return( FALSE );
42
43 lu->status = BFP_STATUS_SUCCESS;
44 lu->max_Bsize = 0; /* The largest NZ-count of the B matrix */
45 lu->max_colcount = 0; /* The maximum number of user columns in B */
46 lu->max_LUsize = 0; /* The largest NZ-count of LU-files generated */
47 lu->num_refact = 0; /* The number of times the basis has been factored */
48 lu->num_timed_refact = 0;
49 lu->num_dense_refact = 0;
50 lu->num_pivots = 0; /* The number of pivots since last factorization */
51 lu->pcol = NULL;
52 lu->set_Bidentity = FALSE;
53
54 return( TRUE );
55 }
56
57 /* DON'T MODIFY */
bfp_implicitslack(lprec * lp)58 MYBOOL BFP_CALLMODEL bfp_implicitslack(lprec *lp)
59 {
60 return( FALSE );
61 }
62
63 /* DON'T MODIFY */
bfp_colcount(lprec * lp)64 int BFP_CALLMODEL bfp_colcount(lprec *lp)
65 {
66 return(lp->invB->user_colcount);
67 }
68
69
70 /* DON'T MODIFY */
bfp_canresetbasis(lprec * lp)71 MYBOOL BFP_CALLMODEL bfp_canresetbasis(lprec *lp)
72 {
73 return( FALSE );
74 }
75
76
77 /* DON'T MODIFY */
bfp_pivotalloc(lprec * lp,int newsize)78 MYBOOL BFP_CALLMODEL bfp_pivotalloc(lprec *lp, int newsize)
79 {
80 /* Does nothing in the default implementation */
81 return( TRUE );
82 }
83
84
85 /* DON'T MODIFY */
bfp_finishfactorization(lprec * lp)86 void BFP_CALLMODEL bfp_finishfactorization(lprec *lp)
87 {
88 INVrec *lu;
89
90 lu = lp->invB;
91
92 SETMAX(lu->max_colcount, lp->bfp_colcount(lp));
93 SETMAX(lu->max_LUsize, lp->bfp_nonzeros(lp, FALSE));
94
95 /* Signal that we done factorizing/reinverting */
96 lu->is_dirty = FALSE;
97 lp->clear_action(&lp->spx_action, ACTION_REINVERT | ACTION_TIMEDREINVERT);
98 lu->force_refact = FALSE;
99
100 /* Store information about the current inverse */
101 lu->num_pivots = 0;
102
103 }
104
105
106 /* DON'T MODIFY */
bfp_prepareupdate(lprec * lp,int row_nr,int col_nr,REAL * pcol)107 LREAL BFP_CALLMODEL bfp_prepareupdate(lprec *lp, int row_nr, int col_nr, REAL *pcol)
108 /* Was condensecol() in versions of lp_solve before 4.0.1.8 - KE */
109 {
110 LREAL pivValue;
111 INVrec *lu;
112
113 lu = lp->invB;
114
115 /* Store the incoming pivot value for RHS update purposes */
116 lu->col_enter = col_nr; /* The index of the new data column */
117 lu->col_pos = row_nr; /* The basis column to be replaced */
118 lu->col_leave = lp->var_basic[row_nr];
119 if(pcol == NULL)
120 pivValue = 0;
121 else
122 pivValue = pcol[row_nr];
123 lu->theta_enter = pivValue;
124
125 /* Save reference to the elimination vector */
126 lu->pcol = pcol;
127
128 /* Set completion status; but hold if we are reinverting */
129 if(lu->is_dirty != AUTOMATIC)
130 lu->is_dirty = TRUE;
131
132 return( pivValue );
133 }
134
135
136 /* DON'T MODIFY */
bfp_pivotRHS(lprec * lp,LREAL theta,REAL * pcol)137 REAL BFP_CALLMODEL bfp_pivotRHS(lprec *lp, LREAL theta, REAL *pcol)
138 /* This function is used to adjust the RHS in bound swap operations as
139 well as handling the updating of the RHS for normal basis changes.
140 Was rhsmincol(), ie. "rhs minus column" in versions of lp_solve before 4.0.1.8 - KE */
141 {
142 INVrec *lu;
143
144 lu = lp->invB;
145
146 if(pcol == NULL)
147 pcol = lu->pcol;
148
149 if(theta != 0) {
150 register int i, n = lp->rows;
151 register LREAL roundzero = lp->epsvalue;
152 register LREAL *rhs = lp->rhs, rhsmax = 0;
153
154 for(i = 0; i <= n; i++, rhs++, pcol++) {
155 (*rhs) -= theta * (*pcol);
156 my_roundzero(*rhs, roundzero);
157 SETMAX(rhsmax, fabs(*rhs));
158 }
159 lp->rhsmax = rhsmax;
160 }
161
162 if(pcol == lu->pcol)
163 return( lu->theta_enter );
164 else
165 return( 0.0 );
166 }
167
168
169 /* DON'T MODIFY */
bfp_btran_double(lprec * lp,REAL * prow,int * pnzidx,REAL * drow,int * dnzidx)170 void BFP_CALLMODEL bfp_btran_double(lprec *lp, REAL *prow, int *pnzidx, REAL *drow, int *dnzidx)
171 {
172 if(prow != NULL)
173 lp->bfp_btran_normal(lp, prow, pnzidx);
174 if(drow != NULL)
175 lp->bfp_btran_normal(lp, drow, dnzidx);
176 }
177
178