/[ascend]/trunk/base/generic/solver/test/test_slv_common.c
ViewVC logotype

Contents of /trunk/base/generic/solver/test/test_slv_common.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations) (download) (as text)
Mon Oct 31 03:39:15 2005 UTC (18 years, 7 months ago) by jds
File MIME type: text/x-csrc
File size: 44358 byte(s)
- jam build up and limping on Linux (finally).
- fixes to CUnit test suite to compile on Linux (still not operable, though).
1 /*
2 * Unit test functions for ASCEND: solver/slv_common.c
3 *
4 * Copyright (C) 2005 Jerry St.Clair
5 *
6 * This file is part of the Ascend Environment.
7 *
8 * The Ascend Environment is free software; you can redistribute it
9 * and/or modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * The Ascend Environment is distributed in hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with the program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
21 * COPYING.
22 */
23
24 #include <stdio.h>
25 #ifdef __WIN32__
26 #include <io.h>
27 #endif
28 #include "utilities/ascConfig.h"
29 #include "utilities/ascMalloc.h"
30 #include "solver/slv_types.h"
31 #include "solver/rel.h"
32 #include "solver/logrel.h"
33 #include "solver/mtx.h"
34 #include "general/list.h"
35 #include "solver/slv_common.h"
36 #include "CUnit/CUnit.h"
37 #include "test_slv_common.h"
38 #include "assertimpl.h"
39
40 /*
41 * Initializes a vector_data structure.
42 * The new range (low..high) is considered proper if both low and
43 * high are zero or positive, and (low <= high). If the new range is
44 * not proper (or if vec itself is NULL), then no modifications are
45 * made to vec.<br><br>
46 *
47 * If the range is proper then vec->rng is allocated if NULL and then
48 * set using low and high. Then vec->vec is allocated (if NULL) or
49 * reallocated to size (high+1). The data in vec->vec is not
50 * initialized or changed. The member vec->accurate is set to FALSE.
51 *
52 * @param vec Pointer to the vector_data to initialize.
53 * @param low The lower bound of the vector's range.
54 * @param high The upper bound of the vector's range.
55 * @return Returns 0 if the vector is initialized successfully,
56 * 1 if an improper range was specified, 2 if vec is NULL,
57 * and 3 if memory cannot be allocated.
58 */
59 static int init_vector(struct vector_data *vec, int32 low, int32 high)
60 {
61 int32 new_size;
62
63 if ((low < 0) || (high < low))
64 return 1;
65
66 if (NULL == vec)
67 return 2;
68
69 if (NULL == vec->rng) {
70 vec->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t));
71 if (NULL == vec->rng)
72 return 3;
73 }
74 vec->rng = mtx_range(vec->rng, low, high);
75
76 new_size = high + 1;
77 if (NULL == vec->vec) {
78 vec->vec = (real64 *)ascmalloc((new_size)*sizeof(real64));
79 if (NULL == vec->vec) {
80 ascfree(vec->rng);
81 vec->rng = NULL;
82 return 3;
83 }
84 }
85 else {
86 vec->vec = (real64 *)ascrealloc(vec->vec, (new_size)*sizeof(real64));
87 }
88
89 vec->accurate = FALSE;
90 return 0;
91 }
92
93 /*
94 * Returns a new vector_data initialized to the specified range.
95 * This function creates, initializes, and returns a new vector_data
96 * structure. The vector is initialized using init_vector() and
97 * a pointer to the new struct is returned. If the specified range
98 * is improper (see init_vector()) then a valid vector cannot be
99 * created and NULL is returned.<br><br>
100 *
101 * Destruction of the returned vector_data is the responsibility of
102 * the caller. destroy_vector() may be used for this purpose.
103 *
104 * @param low The lower bound of the vector's range.
105 * @param high The upper bound of the vector's range.
106 * @return A new initialized vector_data, or NULL if one could
107 * not be created.
108 */
109 static struct vector_data *create_vector(int32 low, int32 high)
110 {
111 struct vector_data *result;
112
113 result = (struct vector_data *)ascmalloc(sizeof(struct vector_data));
114 if (NULL == result)
115 return NULL;
116
117 result->rng = NULL;
118 result->vec = NULL;
119 if (0 != init_vector(result, low, high)) {
120 ascfree(result);
121 result = NULL;
122 }
123 return result;
124 }
125
126 /*
127 * Destroys a vector and its assocated data.
128 * Deallocates any memory held in vec->rng and vec->vec,
129 * and then deallocates the vector itself.
130 *
131 * @param vec Pointer to the vector_data to destroy.
132 */
133 static void destroy_vector(struct vector_data *vec)
134 {
135 if (NULL != vec) {
136 if (NULL != vec->rng)
137 ascfree(vec->rng);
138 if (NULL != vec->vec)
139 ascfree(vec->vec);
140 ascfree(vec);
141 }
142 }
143
144 /*
145 * Independent calculation of a vector dot product.
146 * Nothing fancy, no validation of input. Assumes valid vectors.
147 */
148 real64 slow_dot_product(struct vector_data *vec1, struct vector_data *vec2)
149 {
150 int32 i;
151 real64 product = 0.0;
152 real64 *p1 = vec1->vec + vec1->rng->low;
153 real64 *p2 = vec2->vec + vec2->rng->low;
154 int32 len = vec1->rng->high - vec1->rng->low + 1;
155
156 for (i=0 ; i<len ; ++i, ++p1, ++p2)
157 product += *p1 * *p2;
158
159 return product;
160 }
161
162 /*
163 * This function tests the slv_common.c functions and data structures.
164 * Note that some of the implementation declarated in slv_common.h is
165 * defined in slv.c rather than slv_common.c. This subset of slv_common.h
166 * will be tested along with slv.c elsewhere.
167 */
168 static void test_slv_common(void)
169 {
170 struct vector_data *pvec1;
171 struct vector_data *pvec2;
172 mtx_matrix_t mtx;
173 real64 rarray[100];
174 int i;
175 unsigned long prior_meminuse;
176 unsigned long cur_meminuse;
177 int i_initialized_lists = FALSE;
178
179 #ifdef NDEBUG
180 CU_FAIL("test_slv_common() compiled with NDEBUG - some features not tested.");
181 #endif
182
183 prior_meminuse = ascmeminuse();
184
185 /* set up pooling & recycling */
186 if (FALSE == gl_pool_initialized()) {
187 gl_init();
188 gl_init_pool();
189 i_initialized_lists = TRUE;
190 }
191
192 for (i=0 ; i<100 ; ++i) { /* create some reals to use later */
193 rarray[i+1] = (real64)pow(i+1, i+1);
194 }
195
196 /* test create_vector(), destroy_vector() */
197
198 cur_meminuse = ascmeminuse();
199 pvec1 = create_vector(-1, 0); /* error - low < 0 */
200 CU_TEST(NULL == pvec1);
201
202 destroy_vector(pvec1);
203 CU_TEST(cur_meminuse == ascmeminuse());
204
205 cur_meminuse = ascmeminuse();
206 pvec1 = create_vector(0, -1); /* error - high < 0 */
207 CU_TEST(NULL == pvec1);
208
209 destroy_vector(pvec1);
210 CU_TEST(cur_meminuse == ascmeminuse());
211
212 cur_meminuse = ascmeminuse();
213 pvec1 = create_vector(10, 0); /* error - low > high */
214 CU_TEST(NULL == pvec1);
215
216 destroy_vector(pvec1);
217 CU_TEST(cur_meminuse == ascmeminuse());
218
219 cur_meminuse = ascmeminuse();
220 pvec1 = create_vector(0, 0); /* ok - low == high */
221 CU_TEST_FATAL(NULL != pvec1);
222 CU_TEST_FATAL(NULL != pvec1->rng);
223 CU_TEST(0 == pvec1->rng->low);
224 CU_TEST(0 == pvec1->rng->high);
225 CU_TEST(NULL != pvec1->vec);
226 CU_TEST(FALSE == pvec1->accurate);
227 #ifdef MALLOC_DEBUG
228 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
229 CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
230 CU_TEST(2 == AllocatedMemory(pvec1->vec, sizeof(real64)));
231 #else
232 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
233 CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
234 CU_TEST(1 == AllocatedMemory(pvec1->vec, sizeof(real64)));
235 #endif
236
237 destroy_vector(pvec1);
238 CU_TEST(0 == AllocatedMemory(pvec1, 0));
239 CU_TEST(cur_meminuse == ascmeminuse());
240
241 cur_meminuse = ascmeminuse();
242 pvec1 = create_vector(0, 10); /* ok - low < high */
243 CU_TEST_FATAL(NULL != pvec1);
244 CU_TEST_FATAL(NULL != pvec1->rng);
245 CU_TEST(0 == pvec1->rng->low);
246 CU_TEST(10 == pvec1->rng->high);
247 CU_TEST(NULL != pvec1->vec);
248 CU_TEST(FALSE == pvec1->accurate);
249 #ifdef MALLOC_DEBUG
250 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
251 CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
252 CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
253 #else
254 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
255 CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
256 CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
257 #endif
258
259 destroy_vector(pvec1);
260 CU_TEST(0 == AllocatedMemory(pvec1, 0));
261 CU_TEST(cur_meminuse == ascmeminuse());
262
263 /* test init_vector() */
264
265 cur_meminuse = ascmeminuse();
266 CU_TEST(2 == init_vector(NULL, 0, 10)); /* error - NULL vec */
267 CU_TEST(cur_meminuse == ascmeminuse());
268
269 cur_meminuse = ascmeminuse();
270 pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */
271 CU_TEST_FATAL(NULL != pvec1);
272 pvec1->rng = NULL;
273 pvec1->vec = NULL;
274 pvec1->accurate = TRUE;
275
276 CU_TEST(1 == init_vector(pvec1, -1, 10)); /* error - low < 0 */
277 CU_TEST(NULL == pvec1->rng);
278 CU_TEST(NULL == pvec1->vec);
279 CU_TEST(TRUE == pvec1->accurate);
280 #ifdef MALLOC_DEBUG
281 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
282 #else
283 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
284 #endif
285
286 destroy_vector(pvec1);
287 CU_TEST(0 == AllocatedMemory(pvec1, 0));
288 CU_TEST(cur_meminuse == ascmeminuse());
289
290 cur_meminuse = ascmeminuse();
291 pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */
292 CU_TEST_FATAL(NULL != pvec1);
293 pvec1->rng = NULL;
294 pvec1->vec = NULL;
295 pvec1->accurate = TRUE;
296
297 CU_TEST(1 == init_vector(pvec1, 10, -1)); /* error - high < 0 */
298 CU_TEST(NULL == pvec1->rng);
299 CU_TEST(NULL == pvec1->vec);
300 CU_TEST(TRUE == pvec1->accurate);
301 #ifdef MALLOC_DEBUG
302 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
303 #else
304 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
305 #endif
306
307 destroy_vector(pvec1);
308 CU_TEST(0 == AllocatedMemory(pvec1, 0));
309 CU_TEST(cur_meminuse == ascmeminuse());
310
311 cur_meminuse = ascmeminuse();
312 pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */
313 CU_TEST_FATAL(NULL != pvec1);
314 pvec1->rng = NULL;
315 pvec1->vec = NULL;
316 pvec1->accurate = TRUE;
317
318 CU_TEST(0 == init_vector(pvec1, 10, 10)); /* ok - low == high */
319 CU_TEST_FATAL(NULL != pvec1->rng);
320 CU_TEST(10 == pvec1->rng->low);
321 CU_TEST(10 == pvec1->rng->high);
322 CU_TEST(NULL != pvec1->vec);
323 CU_TEST(FALSE == pvec1->accurate);
324 #ifdef MALLOC_DEBUG
325 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
326 CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
327 CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
328 #else
329 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
330 CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
331 CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
332 #endif
333
334 destroy_vector(pvec1);
335 CU_TEST(0 == AllocatedMemory(pvec1, 0));
336 CU_TEST(cur_meminuse == ascmeminuse());
337
338 cur_meminuse = ascmeminuse();
339 pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */
340 CU_TEST_FATAL(NULL != pvec1);
341 pvec1->rng = NULL;
342 pvec1->vec = NULL;
343 pvec1->accurate = TRUE;
344
345 CU_TEST(0 == init_vector(pvec1, 10, 100)); /* ok - low < high */
346 CU_TEST_FATAL(NULL != pvec1->rng);
347 CU_TEST(10 == pvec1->rng->low);
348 CU_TEST(100 == pvec1->rng->high);
349 CU_TEST(NULL != pvec1->vec);
350 CU_TEST(FALSE == pvec1->accurate);
351 #ifdef MALLOC_DEBUG
352 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
353 CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
354 CU_TEST(2 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64)));
355 #else
356 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
357 CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
358 CU_TEST(1 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64)));
359 #endif
360
361 destroy_vector(pvec1);
362 CU_TEST(0 == AllocatedMemory(pvec1, 0));
363 CU_TEST(cur_meminuse == ascmeminuse());
364
365 cur_meminuse = ascmeminuse();
366 pvec1 = create_vector(0,0); /* create a vector with data */
367 CU_TEST_FATAL(NULL != pvec1);
368 #ifdef MALLOC_DEBUG
369 CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
370 CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
371 CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
372 #else
373 CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data)));
374 CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t)));
375 CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
376 #endif
377
378 pvec1->accurate = TRUE;
379 pvec1->vec[0] = rarray[0];
380
381 CU_TEST(1 == init_vector(pvec1, -1, 100)); /* error - low < 0 */
382 CU_TEST_FATAL(NULL != pvec1->rng);
383 CU_TEST(0 == pvec1->rng->low);
384 CU_TEST(0 == pvec1->rng->high);
385 CU_TEST_FATAL(NULL != pvec1->vec);
386 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
387 CU_TEST(TRUE == pvec1->accurate);
388 #ifdef MALLOC_DEBUG
389 CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
390 #else
391 CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
392 #endif
393
394 CU_TEST(1 == init_vector(pvec1, 1, 0)); /* error - high < low */
395 CU_TEST_FATAL(NULL != pvec1->rng);
396 CU_TEST(0 == pvec1->rng->low);
397 CU_TEST(0 == pvec1->rng->high);
398 CU_TEST_FATAL(NULL != pvec1->vec);
399 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
400 CU_TEST(TRUE == pvec1->accurate);
401 #ifdef MALLOC_DEBUG
402 CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
403 #else
404 CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64)));
405 #endif
406
407 CU_TEST(0 == init_vector(pvec1, 0, 1)); /* ok - high > low */
408 CU_TEST_FATAL(NULL != pvec1->rng);
409 CU_TEST(0 == pvec1->rng->low);
410 CU_TEST(1 == pvec1->rng->high);
411 CU_TEST_FATAL(NULL != pvec1->vec);
412 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
413 CU_TEST(FALSE == pvec1->accurate);
414 #ifdef MALLOC_DEBUG
415 CU_TEST(2 == AllocatedMemory(pvec1->vec, 2 * sizeof(real64)));
416 #else
417 CU_TEST(1 == AllocatedMemory(pvec1->vec, 2 * sizeof(real64)));
418 #endif
419
420 pvec1->accurate = TRUE;
421 pvec1->vec[1] = rarray[1];
422
423 CU_TEST(0 == init_vector(pvec1, 9, 10)); /* ok - high > low */
424 CU_TEST_FATAL(NULL != pvec1->rng);
425 CU_TEST(9 == pvec1->rng->low);
426 CU_TEST(10 == pvec1->rng->high);
427 CU_TEST_FATAL(NULL != pvec1->vec);
428 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
429 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[1], rarray[1], 0.00001);
430 CU_TEST(FALSE == pvec1->accurate);
431 #ifdef MALLOC_DEBUG
432 CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
433 #else
434 CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64)));
435 #endif
436
437 destroy_vector(pvec1);
438 CU_TEST(0 == AllocatedMemory(pvec1, 0));
439 CU_TEST(cur_meminuse == ascmeminuse());
440
441 /* test slv_zero_vector() */
442
443 //#ifndef ASC_NO_ASSERTIONS
444 // asc_assert_catch(TRUE); /* prepare to test assertions */
445
446 // asc_assert_reset();
447 // if (0 == setjmp(g_asc_test_env))
448 // slv_zero_vector(NULL); /* error - NULL vec */
449 // CU_TEST(TRUE == asc_assert_failed());
450
451 // pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */
452 // CU_TEST_FATAL(NULL != pvec1);
453 // pvec1->rng = NULL;
454 // pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64));
455
456 // asc_assert_reset();
457 // if (0 == setjmp(g_asc_test_env))
458 // slv_zero_vector(pvec1); /* error - NULL vec->rng */
459 // CU_TEST(TRUE == asc_assert_failed());
460
461 // pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t));
462 // ascfree(pvec1->vec);
463 // pvec1->vec = NULL;
464
465 // asc_assert_reset();
466 // if (0 == setjmp(g_asc_test_env))
467 // slv_zero_vector(pvec1); /* error - NULL vec->vec */
468 // CU_TEST(TRUE == asc_assert_failed());
469
470 // pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64));
471 // pvec1->rng->low = -1;
472 // pvec1->rng->high = 10;
473
474 // asc_assert_reset();
475 // if (0 == setjmp(g_asc_test_env))
476 // slv_zero_vector(pvec1); /* error - low < 0 */
477 // CU_TEST(TRUE == asc_assert_failed());
478
479 // pvec1->rng->low = 11;
480
481 // asc_assert_reset();
482 // if (0 == setjmp(g_asc_test_env))
483 // slv_zero_vector(pvec1); /* error - low > high */
484 // CU_TEST(TRUE == asc_assert_failed());
485
486 // destroy_vector(pvec1);
487
488 // asc_assert_catch(FALSE); /* done testing assertions */
489 //#endif /* !ASC_NO_ASSERTIONS */
490
491 pvec1 = create_vector(0,0); /* create & initialize a 1-element vector */
492 CU_TEST_FATAL(NULL != pvec1);
493
494 pvec1->vec[0] = rarray[0];
495 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
496
497 slv_zero_vector(pvec1);
498 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001);
499
500 CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension to larger vector */
501
502 for (i=0 ; i<10 ; ++i) {
503 pvec1->vec[i] = rarray[i]; /* initialize & check the data */
504 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001);
505 }
506
507 slv_zero_vector(pvec1);
508 for (i=0 ; i<10 ; ++i) {
509 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], 0.0, 0.00001); /* all data should now be 0.0 */
510 }
511
512 for (i=0 ; i<10 ; ++i) {
513 pvec1->vec[i] = rarray[i]; /* initialize again */
514 }
515
516 pvec1->rng->low = 5;
517 pvec1->rng->high = 7;
518
519 slv_zero_vector(pvec1);
520 for (i=0 ; i<5 ; ++i) {
521 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001);
522 }
523 for (i=5 ; i<8 ; ++i) {
524 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], 0.0, 0.00001);
525 }
526 for (i=8 ; i<10 ; ++i) {
527 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001);
528 }
529
530 destroy_vector(pvec1);
531
532 /* test slv_copy_vector() */
533
534 //#ifndef ASC_NO_ASSERTIONS
535 // asc_assert_catch(TRUE); /* prepare to test assertions */
536
537 // pvec1 = create_vector(0,10);
538 // CU_TEST_FATAL(NULL != pvec1);
539
540 // asc_assert_reset();
541 // if (0 == setjmp(g_asc_test_env))
542 // slv_copy_vector(NULL, pvec1); /* error - NULL srcvec */
543 // CU_TEST(TRUE == asc_assert_failed());
544
545 // asc_assert_reset();
546 // if (0 == setjmp(g_asc_test_env))
547 // slv_copy_vector(pvec1, NULL); /* error - NULL destvec */
548 // CU_TEST(TRUE == asc_assert_failed());
549
550 // pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */
551 // CU_TEST_FATAL(NULL != pvec2);
552 // pvec2->rng = NULL;
553 // pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64));
554
555 // asc_assert_reset();
556 // if (0 == setjmp(g_asc_test_env))
557 // slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->rng */
558 // CU_TEST(TRUE == asc_assert_failed());
559
560 // asc_assert_reset();
561 // if (0 == setjmp(g_asc_test_env))
562 // slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->rng */
563 // CU_TEST(TRUE == asc_assert_failed());
564
565 // pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t));
566 // ascfree(pvec2->vec);
567 // pvec2->vec = NULL;
568
569 // asc_assert_reset();
570 // if (0 == setjmp(g_asc_test_env))
571 // slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->vec */
572 // CU_TEST(TRUE == asc_assert_failed());
573
574 // asc_assert_reset();
575 // if (0 == setjmp(g_asc_test_env))
576 // slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->vec */
577 // CU_TEST(TRUE == asc_assert_failed());
578
579 // pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64));
580 // pvec2->rng->low = -1;
581 // pvec2->rng->high = 10;
582
583 // asc_assert_reset();
584 // if (0 == setjmp(g_asc_test_env))
585 // slv_zero_vector(pvec2, pvec1); /* error - srcvec->rng->low < 0 */
586 // CU_TEST(TRUE == asc_assert_failed());
587
588 // asc_assert_reset();
589 // if (0 == setjmp(g_asc_test_env))
590 // slv_zero_vector(pvec1, pvec2); /* error - destvec->rng->low < 0 */
591 // CU_TEST(TRUE == asc_assert_failed());
592
593 // pvec2->rng->low = 11;
594
595 // asc_assert_reset();
596 // if (0 == setjmp(g_asc_test_env))
597 // slv_copy_vector(pvec2, pvec1); /* error - srcvec low > high */
598 // CU_TEST(TRUE == asc_assert_failed());
599
600 // destroy_vector(pvec1);
601 // destroy_vector(pvec2);
602
603 // asc_assert_catch(FALSE); /* done testing assertions */
604 //#endif /* !ASC_NO_ASSERTIONS */
605
606 pvec1 = create_vector(0,0); /* create & initialize a 1-element vectors */
607 pvec2 = create_vector(0,0);
608 CU_TEST_FATAL(NULL != pvec1);
609
610 pvec1->vec[0] = rarray[0];
611 pvec2->vec[0] = rarray[5];
612 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
613 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001);
614
615 slv_copy_vector(pvec1, pvec2);
616 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
617 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[0], 0.00001);
618
619 CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension pvec1 to larger vector */
620
621 for (i=0 ; i<10 ; ++i) {
622 pvec1->vec[i] = rarray[i]; /* initialize & check the data */
623 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001);
624 }
625
626 pvec2->vec[0] = rarray[8];
627 slv_copy_vector(pvec2, pvec1); /* copy 1 element*/
628 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[8], 0.00001);
629 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[8], 0.00001);
630 for (i=1 ; i<10 ; ++i) {
631 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* rest of data should be intact */
632 }
633
634 pvec2->vec[0] = rarray[3];
635 pvec1->rng->low = 9;
636 pvec1->rng->high = 9;
637 slv_copy_vector(pvec1, pvec2); /* copy 1 element other way*/
638 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[9], 0.00001);
639 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[8], 0.00001);
640 for (i=1 ; i<10 ; ++i) {
641 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in src should be intact */
642 }
643
644 CU_TEST_FATAL(0 == init_vector(pvec2, 0, 9)); /* redimension pvec2 to larger vector */
645 slv_zero_vector(pvec2); /* zero the destvec */
646 pvec1->rng->low = 0;
647 pvec1->rng->high = 9;
648 slv_copy_vector(pvec1, pvec2); /* copy all elements */
649 for (i=0 ; i<10 ; ++i) {
650 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], pvec2->vec[i], 0.00001); /* data should be the same */
651 }
652
653 for (i=0 ; i<10 ; ++i) {
654 pvec2->vec[i] = rarray[9-i]; /* reinitialize & check the data */
655 }
656 pvec2->rng->low = 3;
657 pvec2->rng->high = 6;
658 slv_copy_vector(pvec2, pvec1); /* copy a subset of elements to start of destvec */
659 for (i=3 ; i<7 ; ++i) {
660 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i-3], rarray[9-i], 0.00001); /* data should be the same */
661 }
662 for (i=4 ; i<10 ; ++i) {
663 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data should be the same */
664 }
665
666 destroy_vector(pvec1);
667 destroy_vector(pvec2);
668
669 /* test slv_inner_product() */
670
671 //#ifndef ASC_NO_ASSERTIONS
672 // asc_assert_catch(TRUE); /* prepare to test assertions */
673
674 // pvec1 = create_vector(0,10);
675 // CU_TEST_FATAL(NULL != pvec1);
676
677 // asc_assert_reset();
678 // if (0 == setjmp(g_asc_test_env))
679 // slv_inner_product(NULL, pvec1); /* error - NULL vec1 */
680 // CU_TEST(TRUE == asc_assert_failed());
681
682 // asc_assert_reset();
683 // if (0 == setjmp(g_asc_test_env))
684 // slv_inner_product(pvec1, NULL); /* error - NULL vec2 */
685 // CU_TEST(TRUE == asc_assert_failed());
686
687 // pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */
688 // CU_TEST_FATAL(NULL != pvec2);
689 // pvec2->rng = NULL;
690 // pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64));
691
692 // asc_assert_reset();
693 // if (0 == setjmp(g_asc_test_env))
694 // slv_inner_product(pvec2, pvec1); /* error - NULL vec1->rng */
695 // CU_TEST(TRUE == asc_assert_failed());
696
697 // asc_assert_reset();
698 // if (0 == setjmp(g_asc_test_env))
699 // slv_inner_product(pvec1, pvec2); /* error - NULL vec2->rng */
700 // CU_TEST(TRUE == asc_assert_failed());
701
702 // pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t));
703 // ascfree(pvec2->vec);
704 // pvec2->vec = NULL;
705
706 // asc_assert_reset();
707 // if (0 == setjmp(g_asc_test_env))
708 // slv_inner_product(pvec2, pvec1); /* error - NULL vec1->vec */
709 // CU_TEST(TRUE == asc_assert_failed());
710
711 // asc_assert_reset();
712 // if (0 == setjmp(g_asc_test_env))
713 // slv_inner_product(pvec1, pvec2); /* error - NULL vec2->vec */
714 // CU_TEST(TRUE == asc_assert_failed());
715
716 // pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64));
717 // pvec2->rng->low = -1;
718 // pvec2->rng->high = 10;
719
720 // asc_assert_reset();
721 // if (0 == setjmp(g_asc_test_env))
722 // slv_inner_product(pvec2, pvec1); /* error - vec1->rng->low < 0 */
723 // CU_TEST(TRUE == asc_assert_failed());
724
725 // asc_assert_reset();
726 // if (0 == setjmp(g_asc_test_env))
727 // slv_inner_product(pvec1, pvec2); /* error - vec2->rng->low < 0 */
728 // CU_TEST(TRUE == asc_assert_failed());
729
730 // pvec2->rng->low = 11;
731
732 // asc_assert_reset();
733 // if (0 == setjmp(g_asc_test_env))
734 // slv_inner_product(pvec2, pvec1); /* error - vec1 low > high */
735 // CU_TEST(TRUE == asc_assert_failed());
736
737 // destroy_vector(pvec1);
738 // destroy_vector(pvec2);
739
740 // asc_assert_catch(FALSE); /* done testing assertions */
741 //#endif /* !ASC_NO_ASSERTIONS */
742
743 pvec1 = create_vector(0,0); /* create & initialize a 1-element vectors */
744 pvec2 = create_vector(0,0);
745 CU_TEST_FATAL(NULL != pvec1);
746 CU_TEST_FATAL(NULL != pvec2);
747
748 pvec1->vec[0] = rarray[0];
749 pvec2->vec[0] = rarray[5];
750 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
751 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001);
752
753 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001);
754 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001);
755 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001);
756 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001);
757
758 CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension vectors larger */
759 CU_TEST_FATAL(0 == init_vector(pvec2, 0, 9));
760
761 for (i=0 ; i<10 ; ++i) {
762 pvec1->vec[i] = rarray[i]; /* initialize & check the data */
763 pvec2->vec[i] = 2.0;
764 }
765 /* check entire vectors */
766 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001);
767 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001);
768
769 pvec1->rng->low = 9;
770 pvec1->rng->high = 9;
771 pvec2->rng->low = 5;
772 pvec2->rng->high = 5; /* check 1 element subrange */
773 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001);
774 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001);
775
776 pvec1->rng->low = 0;
777 pvec1->rng->high = 3;
778 pvec2->rng->low = 2;
779 pvec2->rng->high = 5; /* check 4 element subrange */
780 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001);
781 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001);
782
783 for (i=1 ; i<10 ; ++i) {
784 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */
785 CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[i], 2.0, 0.00001);
786 }
787
788 for (i=0 ; i<10 ; ++i) {
789 pvec1->vec[i] = rarray[i]; /* initialize & check the data */
790 pvec2->vec[i] = rarray[9-i];
791 }
792 /* check entire vectors */
793 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001);
794 CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001);
795
796 destroy_vector(pvec1);
797 destroy_vector(pvec2);
798
799 /* test slv_square_norm() */
800
801 //#ifndef ASC_NO_ASSERTIONS
802 // asc_assert_catch(TRUE); /* prepare to test assertions */
803
804 // asc_assert_reset();
805 // if (0 == setjmp(g_asc_test_env))
806 // slv_square_norm(NULL); /* error - NULL vec */
807 // CU_TEST(TRUE == asc_assert_failed());
808
809 // pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */
810 // CU_TEST_FATAL(NULL != pvec1);
811 // pvec1->rng = NULL;
812 // pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64));
813
814 // asc_assert_reset();
815 // if (0 == setjmp(g_asc_test_env))
816 // slv_square_norm(pvec1); /* error - NULL vec->rng */
817 // CU_TEST(TRUE == asc_assert_failed());
818
819 // pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t));
820 // ascfree(pvec1->vec);
821 // pvec1->vec = NULL;
822
823 // asc_assert_reset();
824 // if (0 == setjmp(g_asc_test_env))
825 // slv_square_norm(pvec1); /* error - NULL vec->vec */
826 // CU_TEST(TRUE == asc_assert_failed());
827
828 // pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64));
829 // pvec1->rng->low = -1;
830 // pvec1->rng->high = 10;
831
832 // asc_assert_reset();
833 // if (0 == setjmp(g_asc_test_env))
834 // slv_square_norm(pvec1); /* error - vec->rng->low < 0 */
835 // CU_TEST(TRUE == asc_assert_failed());
836
837 // pvec1->rng->low = 11;
838
839 // asc_assert_reset();
840 // if (0 == setjmp(g_asc_test_env))
841 // slv_square_norm(pvec1); /* error - vec low > high */
842 // CU_TEST(TRUE == asc_assert_failed());
843
844 // destroy_vector(pvec1);
845
846 // asc_assert_catch(FALSE); /* done testing assertions */
847 //#endif /* !ASC_NO_ASSERTIONS */
848
849 pvec1 = create_vector(0,0); /* create & initialize a 1-element vector */
850 CU_TEST_FATAL(NULL != pvec1);
851
852 pvec1->vec[0] = 0.0;
853 CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001);
854 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001);
855
856 pvec1->vec[0] = rarray[7];
857 CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001);
858 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[7], 0.00001);
859
860 CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension vectors larger */
861
862 for (i=0 ; i<10 ; ++i) {
863 pvec1->vec[i] = rarray[i]; /* initialize the data */
864 }
865 /* check entire vectors */
866 CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001);
867
868 pvec1->rng->low = 9;
869 pvec1->rng->high = 9;
870 CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001);
871
872 pvec1->rng->low = 0;
873 pvec1->rng->high = 3;
874 CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001);
875
876 for (i=1 ; i<10 ; ++i) {
877 CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */
878 }
879 slv_write_vector(stdout, pvec1);
880 destroy_vector(pvec1);
881
882 /* test slv_matrix_product() */
883
884 mtx = mtx_create();
885
886
887 mtx_destroy(mtx);
888
889 /*
890
891 extern void slv_matrix_product(mtx_matrix_t mtx,
892 struct vector_data *vec,
893 struct vector_data *prod,
894 real64 scale,
895 boolean transpose);
896
897 * Calculates the product of a vector, matrix, and scale factor.
898 * Stores prod := (scale)*(mtx)*(vec) if transpose = FALSE,
899 * or prod := (scale)*(mtx-transpose)(vec) if transpose = TRUE.
900 * vec and prod must be completely different.
901 * If (!transpose) vec->vec is assumed indexed by current col and
902 * prod->vec is indexed by current row of mtx.
903 * If (transpose) vec->vec is assumed indexed by current row and
904 * prod->vec is indexed by current col of mtx.
905 * The following are not allowed and are checked by assertion:
906 * - NULL mtx
907 * - NULL vec
908 * - NULL vec->rng
909 * - NULL vec->vec
910 * - vec->rng->low < 0
911 * - vec->rng->low > vec->rng->high
912 * - NULL prod
913 * - NULL prod->rng
914 * - NULL prod->vec
915 * - prod->rng->low < 0
916 * - prod->rng->low > prod->rng->high
917 *
918 * @param mtx The matrix for the product.
919 * @param vec The vector for the product.
920 * @param prod The vector to receive the matrix product.
921 * @param scale The scale factor by which to multiply the matrix product.
922 * @param transpose Flag for whether to use mtx or its transpose.
923 *
924 * @todo solver/slv_common:slv_mtx_product needs attention -
925 * does it go into mtx?
926
927
928 extern void slv_write_vector(FILE *fp, struct vector_data *vec);
929 * Write vector information to a file stream.
930 * Prints general information about the vector followed by the
931 * values in the range of the vector to file fp.
932 *
933 * @param fp The file stream to receive the report.
934 * @param vec The vector on which to report.
935
936
937 extern real64 slv_dot(int32 len, const real64 *a1, const real64 *a2);
938
939 * Calculates the dot product of 2 arrays of real64.
940 * This is an optimized routine (loop unrolled). It takes
941 * advantage of identical vectors. The 2 arrays must have
942 * at least len elements.
943 * The following are not allowed and are checked by assertion:
944 * - NULL a1
945 * - NULL a2
946 * - len < 0
947 *
948 * The same algorithm is used inside slv_inner_product(), so there
949 * is no need to use this function directly if you are using the
950 * vector_data type.
951 *
952 * @param len The length of the 2 arrays.
953 * @param a1 The 1st array for the dot product.
954 * @param a2 The 2nd array for the dot product.
955 * @param a2 The 2nd array for the dot product.
956
957 * --------------------------------
958 * General input/output routines
959 * --------------------------------
960
961 extern FILE *slv_get_output_file(FILE *fp);
962 *<
963 * Checks a file pointer, and if NULL returns a pointer to the nul device.
964 * If you are in environment that doesn't have something like
965 * /dev/null (nul on Windows), you'd better be damn sure your
966 * sys->p.output.*_important are not NULL.
967 *
968 * @param fp The file stream to check.
969 * @return fp if it is not NULL, a pointer to the nul device otherwise.
970
971
972
973 * FILE pointer macros.
974 * fp = MIF(sys)
975 * fp = LIF(sys)
976 * fp = PMIF(sys)
977 * fp = PLIF(sys)
978 * or fprintf(MIF(sys),"stuff",data...);
979 * Use of these is requested on grounds of readability but not required.
980 * MIF and LIF are macros, which means any specific solver interface
981 * to ASCEND can use them, since all interfaces are supposed to
982 * support a parameters structure p somewhere in a larger system
983 * structure (sys) they keep privately.
984 * Use the PMIF or PLIF flavors if the parameters sys->p is a pointer
985 * rather than a in-struct member.
986
987 #define MIF(sys) slv_get_output_file( (sys)->p.output.more_important )
988 *<
989 * Retrieve the "more important" output file for a system.
990 * sys must exist and contain an element p of type slv_parameters_t.
991 *
992 * @param sys The slv_system_t to query.
993 * @return A FILE * to the "more important" output file for sys.
994
995 #define LIF(sys) slv_get_output_file( (sys)->p.output.less_important )
996 *<
997 * Retrieve the "less important" output file for a system.
998 * sys must exist and contain an element p of type slv_parameters_t.
999 *
1000 * @param sys The slv_system_t to query.
1001 * @return A FILE * to the "less important" output file for sys.
1002
1003 #define PMIF(sys) slv_get_output_file( (sys)->p->output.more_important )
1004 *<
1005 * Retrieve the "more important" output file for a system.
1006 * sys must exist and contain an element p of type slv_parameters_t*.
1007 *
1008 * @param sys The slv_system_t to query.
1009 * @return A FILE * to the "more important" output file for sys.
1010
1011 #define PLIF(sys) slv_get_output_file( (sys)->p->output.less_important )
1012 *<
1013 * Retrieve the "less important" output file for a system.
1014 * sys must exist and contain an element p of type slv_parameters_t*.
1015 *
1016 * @param sys The slv_system_t to query.
1017 * @return A FILE * to the "less important" output file for sys.
1018
1019
1020 ------------------- begin compiler dependent functions -------------------
1021 #if SLV_INSTANCES
1022
1023 #ifdef NEWSTUFF
1024 extern void slv_print_obj_name(FILE *outfile, obj_objective_t obj);
1025 *<
1026 * Not implemented.
1027 * Prints the name of obj to outfile. If obj_make_name() can't
1028 * generate a name, the global index is printed instead.
1029 * @todo Implement solver/slv_common:slv_print_obj_name() or remove prototype.
1030
1031 #endif
1032 extern void slv_print_rel_name(FILE *outfile,
1033 slv_system_t sys,
1034 struct rel_relation *rel);
1035 *<
1036 * Prints the name of rel to outfile. If rel_make_name() can't
1037 * generate a name, the global index is printed instead.
1038
1039 extern void slv_print_var_name(FILE *outfile,
1040 slv_system_t sys,
1041 struct var_variable *var);
1042 *<
1043 * Prints the name of var to outfile. If var_make_name() can't
1044 * generate a name, the global index is printed instead.
1045
1046 extern void slv_print_logrel_name(FILE *outfile,
1047 slv_system_t sys,
1048 struct logrel_relation *lrel);
1049 *<
1050 * Prints the name of lrel to outfile. If logrel_make_name() can't
1051 * generate a name, the global index is printed instead.
1052
1053 extern void slv_print_dis_name(FILE *outfile,
1054 slv_system_t sys,
1055 struct dis_discrete *dvar);
1056 *<
1057 * Prints the name of dvar to outfile. If dis_make_name() can't
1058 * generate a name, the global index is printed instead.
1059
1060
1061 #ifdef NEWSTUFF
1062 extern void slv_print_obj_index(FILE *outfile, obj_objective_t obj);
1063 *<
1064 * Not implemented.
1065 * Prints the index of obj to outfile.
1066 * @todo Implement solver/slv_common:slv_print_obj_index() or remove prototype.
1067
1068 #endif
1069 extern void slv_print_rel_sindex(FILE *outfile, struct rel_relation *rel);
1070 *< Prints the index of rel to outfile.
1071 extern void slv_print_var_sindex(FILE *outfile, struct var_variable *var);
1072 *< Prints the index of var to outfile.
1073 extern void slv_print_logrel_sindex(FILE *outfile, struct logrel_relation *lrel);
1074 *< Prints the index of lrel to outfile.
1075 extern void slv_print_dis_sindex(FILE *outfile, struct dis_discrete *dvar);
1076 *< Prints the index of dvar to outfile.
1077
1078 extern int slv_direct_solve(slv_system_t server,
1079 struct rel_relation *rel,
1080 struct var_variable *var,
1081 FILE *file,
1082 real64 epsilon,
1083 int ignore_bounds,
1084 int scaled);
1085 *<
1086 * Attempts to directly solve the given relation (equality constraint) for
1087 * the given variable, leaving the others fixed. Returns an integer
1088 * signifying the status as one of the following three:
1089 * <pre>
1090 * 0 ==> Unable to determine anything.
1091 * Not symbolically invertible.
1092 * 1 ==> Solution(s) found.
1093 * Variable value set to first found if more than one.
1094 * -1 ==> No solution found.
1095 * Function invertible, but no solution exists satisfying
1096 * var bounds (if active) and the epsilon given.
1097 * </pre>
1098 * The variable bounds will be upheld, unless ignore_bounds=FALSE.
1099 * Residual testing will be against epsilon and either scaled or
1100 * unscaled residual according to scaled (no scale -> 0).
1101 * If file != NULL and there are leftover possible solutions, we
1102 * will write about them to file.
1103 *
1104 * @param server The slv_system_t (mostly ignored).
1105 * @param rel The relation to attempt to solve.
1106 * @param var The variable for which to solve.
1107 * @param file File stream to receive other possible solutions.
1108 * @param epsilon Tolerance for testing convergence.
1109 * @param ignore_bounds If TRUE, ignore bounds on variable.
1110 * @param scaled If TRUE, test scaled residuals against epsilon.
1111
1112
1113 extern int slv_direct_log_solve(slv_system_t sys,
1114 struct logrel_relation *lrel,
1115 struct dis_discrete *dvar,
1116 FILE *file,
1117 int perturb,
1118 struct gl_list_t *instances);
1119 *<
1120 * Attempt to directly solve the given logrelation for the given
1121 * discrete variable, leaving the others fixed. Returns an integer
1122 * signifying the status as one of the following three:
1123 * <pre>
1124 * 0 ==> Unable to determine anything. Bad logrelation or dvar
1125 * 1 ==> Solution found.
1126 * 2 ==> More than one solution found. It does not modify the value
1127 * of dvar. Conflicting.
1128 * -1 ==> No solution found. Inconsistency
1129 * </pre>
1130 * If file != NULL and there are leftover possible solutions, we
1131 * will write about them to file.
1132 * The flag perturb and the gl_list are used to change the truth
1133 * value of some boundaries. This is sometimes useful in
1134 * conditional modeling.
1135 *
1136 * @param sys The slv_system_t (mostly ignored).
1137 * @param lrel The logical relation to attempt to solve.
1138 * @param dvar The discrete variable for which to solve.
1139 * @param file File stream to receive other possible solutions.
1140 * @param perturb If TRUE, perturbs the truth values if necessary to find the solution.
1141 * @param instances List of instances.
1142
1143
1144 #endif
1145 -------------------- END compiler dependent functions --------------------
1146
1147
1148 * --------------------
1149 * lnkmap functions
1150 * --------------------
1151
1152
1153 extern int32 **slv_create_lnkmap(int32 m, int32 n, int32 hl, int32 *hi, int32 *hj);
1154 *<
1155 * Builds a row biased mapping array from the hi,hj lists given.
1156 * The map returned has the following format:
1157 * - map[i] is a vector describing the incidence in row i of the matrix.
1158 * - Let vars=map[i], where vars is int32 *.
1159 * - vars[0]=number of incidences in the relation.
1160 * - For all 0<=k<vars[0]
1161 * - vars[2*k+1]= original column index of some var in the eqn.
1162 * - vars[2*k+2]= the lnk list index of element(i,vars[2*k+1])
1163 *
1164 * The map should only be deallocated by destroy_lnkmap().
1165 * The memory allocation for a lnkmap is done efficiently.<br><br>
1166 *
1167 * These create an odd compressed row mapping, given the hi and hj
1168 * subscript vectors. The primary utility of the lnkmap is that
1169 * it can be traversed rapidly when one wants to conditionally map a row of
1170 * a Harwell style (arbitrarily ordered) link representation
1171 * back into another representation where adding elements to a row
1172 * is easily done.<br><br>
1173 *
1174 * hi and hj should specify a unique incidence pattern, that is no
1175 * duplicate elements are allowed. Rowindex and colindex refer to
1176 * the data in hi,hj.
1177 *
1178 * @param m The number of rows expected. The map returned will be this long.
1179 * @param n The number of columns expected.
1180 * @param hl The length of hi and hj.
1181 * @param hi The eqn indices of a C numbered sparse matrix list.
1182 * @param hj The var indices of a C numbered sparse matrix list.
1183
1184
1185 extern int32 **slv_lnkmap_from_mtx(mtx_matrix_t mtx, int32 len, int32 m);
1186 *<
1187 * Generates a map from a matrix.
1188 * Empty rows and columns are allowed in the matrix.
1189 *
1190 * @param mtx The matrix to map.
1191 * @param m The number of rows expected. The map returned will be this long.
1192 * @param len The number of nonzeros in mtx.
1193 *
1194 * @see slv_create_lnkmap()
1195
1196
1197 extern void slv_destroy_lnkmap(int32 **map);
1198 *<
1199 * Deallocate a map created by slv_create_lnkmap() or slv_destroy_lnkmap().
1200 * destroy_lnkmap() will tolerate a NULL map as input.
1201 *
1202 * @param map The lnkmap to destroy.
1203
1204
1205 extern void slv_write_lnkmap(FILE *fp, int m, int32 **map);
1206 *<
1207 * Prints a link map to a file.
1208 * write_lnkmap() will tolerate a NULL map as input.
1209 *
1210 * @param fp The file stream to receive the report.
1211 * @param m The number of rows in map to print.
1212 * @param map The lnkmap to print.
1213 */
1214
1215
1216
1217 if (TRUE == i_initialized_lists) { /* clean up list system if necessary */
1218 gl_destroy_pool();
1219 }
1220 CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */
1221 }
1222
1223 /*===========================================================================*/
1224 /* Registration information */
1225
1226 static CU_TestInfo slv_common_test_list[] = {
1227 {"test_slv_common", test_slv_common},
1228 CU_TEST_INFO_NULL
1229 };
1230
1231 static CU_SuiteInfo suites[] = {
1232 {"test_solver_slv_common", NULL, NULL, slv_common_test_list},
1233 CU_SUITE_INFO_NULL
1234 };
1235
1236 /*-------------------------------------------------------------------*/
1237 CU_ErrorCode test_register_solver_slv_common(void)
1238 {
1239 return CU_register_suites(suites);
1240 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22