source: trunk/Couenne/src/readnl/invmap.cpp @ 577

Last change on this file since 577 was 577, checked in by pbelotti, 9 years ago

restoring FP for tests. Changing branching point on integer variables with integer value. Fixing large branching points for variables with large (upper/lower) bounds and large LP values. Added debug code to twoImplBounds for check against optimal solutions. Added fictitious objective function of 0 when none is defined. Redeclared size_t in invmap.cpp for compatibility with MSVS.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1/* $Id: invmap.cpp 577 2011-05-21 20:38:48Z pbelotti $
2 *
3 * Name:    invmap.cpp
4 * Author:  Pietro Belotti
5 * Purpose: create a bijection between ASL's efunc and integer to
6 *          inversely map e->op fields into constant operators
7 *
8 * (C) Carnegie-Mellon University, 2006-11.
9 * This file is licensed under the Eclipse Public License (EPL)
10 */
11
12#include <stdlib.h>
13
14#include "asl.h"
15#include "opcode.hd"
16#include "nlp.h"
17#include "r_opn.hd"
18
19/* couples an ASL function pointer with the relative operator constant */
20
21typedef struct {
22  efunc *fp;
23  int    op;
24} AslCouPair;
25
26
27/* compare two AslCoupair's, used in qsort and bsearch below */
28
29/* AW: 2007-06-11: changed b/c of problems with MSVC++ */
30/* inline int pair_compare (const void *p1, const void *p2) { */
31static int pair_compare (const void *p1, const void *p2) {
32
33  /* FIX! weak cast for 64 bit machines */
34
35  register size_t f1 = Intcast (((AslCouPair *) p1) -> fp); 
36  register size_t f2 = Intcast (((AslCouPair *) p2) -> fp); 
37
38  if      (f1 < f2) return -1;
39  else if (f1 > f2) return  1;
40  else return 0;
41}
42
43
44/* array of pairs (efunc2*, int) that relates all operators */
45
46AslCouPair opmap [N_OPS];
47
48
49/* binary search to get operator number from its efunc2* (the type of e->op) */
50
51size_t getOperator (efunc *f) {
52
53  static char first_call = 1;
54  AslCouPair key, *res;
55
56  /* FIX cast for 64 bit machines */
57
58  if ((Intcast f <  N_OPS) && 
59      (Intcast f > -N_OPS))
60    return Intcast f;
61
62  key.fp = f;
63
64  if (first_call) { /* opmap is still empty, fill it using values from r_ops [] */
65
66    register int i=0;
67    register AslCouPair *ops = opmap;
68
69    /* fill opmap vector with inverse correspondence pairs efunc -> int */
70    while (i<N_OPS) {
71      ops -> fp = r_ops [ops -> op = i++];
72      ops++;
73    }
74
75    /* sort opmap for later use with bsearch */
76    qsort (opmap, N_OPS, sizeof (AslCouPair), pair_compare);
77    first_call = 0;
78  }
79
80  /* find int operator through binary search */
81  res = (AslCouPair *) bsearch (&key, opmap, N_OPS, sizeof (AslCouPair), pair_compare);
82
83  if (!res) 
84    return -1;
85
86  return res -> op;
87}
Note: See TracBrowser for help on using the repository browser.