lemon-project-template-glpk

diff deps/glpk/src/minisat/minisat.h @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/deps/glpk/src/minisat/minisat.h	Sun Nov 06 20:59:10 2011 +0100
     1.3 @@ -0,0 +1,230 @@
     1.4 +/* minisat.h */
     1.5 +
     1.6 +/* Modified by Andrew Makhorin <mao@gnu.org>, August 2011 */
     1.7 +
     1.8 +/***********************************************************************
     1.9 +*  MiniSat -- Copyright (c) 2005, Niklas Sorensson
    1.10 +*  http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
    1.11 +*
    1.12 +*  Permission is hereby granted, free of charge, to any person
    1.13 +*  obtaining a copy of this software and associated documentation files
    1.14 +*  (the "Software"), to deal in the Software without restriction,
    1.15 +*  including without limitation the rights to use, copy, modify, merge,
    1.16 +*  publish, distribute, sublicense, and/or sell copies of the Software,
    1.17 +*  and to permit persons to whom the Software is furnished to do so,
    1.18 +*  subject to the following conditions:
    1.19 +*
    1.20 +*  The above copyright notice and this permission notice shall be
    1.21 +*  included in all copies or substantial portions of the Software.
    1.22 +*
    1.23 +*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.24 +*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.25 +*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    1.26 +*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
    1.27 +*  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    1.28 +*  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    1.29 +*  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    1.30 +*  SOFTWARE.
    1.31 +***********************************************************************/
    1.32 +/* Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko */
    1.33 +
    1.34 +#ifndef MINISAT_H
    1.35 +#define MINISAT_H
    1.36 +
    1.37 +/*====================================================================*/
    1.38 +/* Simple types: */
    1.39 +
    1.40 +typedef int bool;
    1.41 +
    1.42 +#define true  1
    1.43 +#define false 0
    1.44 +
    1.45 +typedef int  lit;
    1.46 +#if 0 /* by mao */
    1.47 +typedef char lbool;
    1.48 +#else
    1.49 +typedef int lbool;
    1.50 +#endif
    1.51 +
    1.52 +#define var_Undef (int)(-1)
    1.53 +#define lit_Undef (lit)(-2)
    1.54 +
    1.55 +#define l_Undef (lbool)0
    1.56 +#define l_True  (lbool)1
    1.57 +#define l_False (lbool)(-1)
    1.58 +
    1.59 +#define toLit(v) (lit)((v) + (v))
    1.60 +#define lit_neg(l) (lit)((l) ^ 1)
    1.61 +#define lit_var(l) (int)((l) >> 1)
    1.62 +#define lit_sign(l) (int)((l) & 1)
    1.63 +
    1.64 +/*====================================================================*/
    1.65 +/* Vectors: */
    1.66 +
    1.67 +/* vector of 32-bit intergers (added for 64-bit portability) */
    1.68 +typedef struct /* veci_t */ {
    1.69 +    int    size;
    1.70 +    int    cap;
    1.71 +    int*   ptr;
    1.72 +} veci;
    1.73 +
    1.74 +#define veci_new(v) \
    1.75 +{   (v)->size = 0; \
    1.76 +    (v)->cap  = 4; \
    1.77 +    (v)->ptr  = (int*)malloc(sizeof(int)*(v)->cap); \
    1.78 +}
    1.79 +
    1.80 +#define veci_delete(v) free((v)->ptr)
    1.81 +
    1.82 +#define veci_begin(v) ((v)->ptr)
    1.83 +
    1.84 +#define veci_size(v) ((v)->size)
    1.85 +
    1.86 +#define veci_resize(v, k) (void)((v)->size = (k))
    1.87 +/* only safe to shrink !! */
    1.88 +
    1.89 +#define veci_push(v, e) \
    1.90 +{   if ((v)->size == (v)->cap) \
    1.91 +    {   int newsize = (v)->cap * 2+1; \
    1.92 +        (v)->ptr = (int*)realloc((v)->ptr,sizeof(int)*newsize); \
    1.93 +        (v)->cap = newsize; \
    1.94 +    } \
    1.95 +    (v)->ptr[(v)->size++] = (e); \
    1.96 +}
    1.97 +
    1.98 +/* vector of 32- or 64-bit pointers */
    1.99 +typedef struct /* vecp_t */ {
   1.100 +    int    size;
   1.101 +    int    cap;
   1.102 +    void** ptr;
   1.103 +} vecp;
   1.104 +
   1.105 +#define vecp_new(v) \
   1.106 +{   (v)->size = 0; \
   1.107 +    (v)->cap  = 4; \
   1.108 +    (v)->ptr  = (void**)malloc(sizeof(void*)*(v)->cap); \
   1.109 +}
   1.110 +
   1.111 +#define vecp_delete(v) free((v)->ptr)
   1.112 +
   1.113 +#define vecp_begin(v) ((v)->ptr)
   1.114 +
   1.115 +#define vecp_size(v) ((v)->size)
   1.116 +
   1.117 +#define vecp_resize(v, k) (void)((v)->size = (k))
   1.118 +/* only safe to shrink !! */
   1.119 +
   1.120 +#define vecp_push(v, e) \
   1.121 +{   if ((v)->size == (v)->cap) \
   1.122 +    {   int newsize = (v)->cap * 2+1; \
   1.123 +        (v)->ptr = (void**)realloc((v)->ptr,sizeof(void*)*newsize); \
   1.124 +        (v)->cap = newsize; \
   1.125 +    } \
   1.126 +    (v)->ptr[(v)->size++] = (e); \
   1.127 +}
   1.128 +
   1.129 +/*====================================================================*/
   1.130 +/* Solver representation: */
   1.131 +
   1.132 +typedef struct /* clause_t */
   1.133 +{
   1.134 +    int size_learnt;
   1.135 +    lit lits[1];
   1.136 +} clause;
   1.137 +
   1.138 +typedef struct /* stats_t */
   1.139 +{
   1.140 +    double   starts, decisions, propagations, inspects, conflicts;
   1.141 +    double   clauses, clauses_literals, learnts, learnts_literals,
   1.142 +             max_literals, tot_literals;
   1.143 +} stats;
   1.144 +
   1.145 +typedef struct /* solver_t */
   1.146 +{
   1.147 +    int      size;          /* nof variables */
   1.148 +    int      cap;           /* size of varmaps */
   1.149 +    int      qhead;         /* Head index of queue. */
   1.150 +    int      qtail;         /* Tail index of queue. */
   1.151 +
   1.152 +    /* clauses */
   1.153 +    vecp     clauses;       /* List of problem constraints.
   1.154 +                               (contains: clause*) */
   1.155 +    vecp     learnts;       /* List of learnt clauses.
   1.156 +                               (contains: clause*) */
   1.157 +
   1.158 +    /* activities */
   1.159 +    double   var_inc;       /* Amount to bump next variable with. */
   1.160 +    double   var_decay;     /* INVERSE decay factor for variable
   1.161 +                               activity: stores 1/decay. */
   1.162 +    float    cla_inc;       /* Amount to bump next clause with. */
   1.163 +    float    cla_decay;     /* INVERSE decay factor for clause
   1.164 +                               activity: stores 1/decay. */
   1.165 +
   1.166 +    vecp*    wlists;
   1.167 +    double*  activity;      /* A heuristic measurement of the activity
   1.168 +                               of a variable. */
   1.169 +    lbool*   assigns;       /* Current values of variables. */
   1.170 +    int*     orderpos;      /* Index in variable order. */
   1.171 +    clause** reasons;
   1.172 +    int*     levels;
   1.173 +    lit*     trail;
   1.174 +
   1.175 +    clause*  binary;        /* A temporary binary clause */
   1.176 +    lbool*   tags;
   1.177 +    veci     tagged;        /* (contains: var) */
   1.178 +    veci     stack;         /* (contains: var) */
   1.179 +
   1.180 +    veci     order;         /* Variable order. (heap) (contains: var) */
   1.181 +    veci     trail_lim;     /* Separator indices for different decision
   1.182 +                               levels in 'trail'. (contains: int) */
   1.183 +    veci     model;         /* If problem is solved, this vector
   1.184 +                               contains the model (contains: lbool). */
   1.185 +
   1.186 +    int      root_level;    /* Level of first proper decision. */
   1.187 +    int      simpdb_assigns;/* Number of top-level assignments at last
   1.188 +                               'simplifyDB()'. */
   1.189 +    int      simpdb_props;  /* Number of propagations before next
   1.190 +                               'simplifyDB()'. */
   1.191 +    double   random_seed;
   1.192 +    double   progress_estimate;
   1.193 +    int      verbosity;     /* Verbosity level.
   1.194 +                               0=silent,
   1.195 +                               1=some progress report,
   1.196 +                               2=everything */
   1.197 +
   1.198 +    stats    stats;
   1.199 +} solver;
   1.200 +
   1.201 +/*====================================================================*/
   1.202 +/* Public interface: */
   1.203 +
   1.204 +#if 1 /* by mao; to keep namespace clean */
   1.205 +#define solver_new        _glp_minisat_new
   1.206 +#define solver_delete     _glp_minisat_delete
   1.207 +#define solver_addclause  _glp_minisat_addclause
   1.208 +#define solver_simplify   _glp_minisat_simplify
   1.209 +#define solver_solve      _glp_minisat_solve
   1.210 +#define solver_nvars      _glp_minisat_nvars
   1.211 +#define solver_nclauses   _glp_minisat_nclauses
   1.212 +#define solver_nconflicts _glp_minisat_nconflicts
   1.213 +#define solver_setnvars   _glp_minisat_setnvars
   1.214 +#define solver_propagate  _glp_minisat_propagate
   1.215 +#define solver_reducedb   _glp_minisat_reducedb
   1.216 +#endif
   1.217 +
   1.218 +solver* solver_new(void);
   1.219 +void    solver_delete(solver* s);
   1.220 +
   1.221 +bool    solver_addclause(solver* s, lit* begin, lit* end);
   1.222 +bool    solver_simplify(solver* s);
   1.223 +bool    solver_solve(solver* s, lit* begin, lit* end);
   1.224 +
   1.225 +int     solver_nvars(solver* s);
   1.226 +int     solver_nclauses(solver* s);
   1.227 +int     solver_nconflicts(solver* s);
   1.228 +
   1.229 +void    solver_setnvars(solver* s,int n);
   1.230 +
   1.231 +#endif
   1.232 +
   1.233 +/* eof */