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