View Javadoc

1   /*******************************************************************************
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * which accompanies this distribution, and is available at
7    *  http://www.eclipse.org/legal/epl-v10.html
8    *
9    * Alternatively, the contents of this file may be used under the terms of
10   * either the GNU Lesser General Public License Version 2.1 or later (the
11   * "LGPL"), in which case the provisions of the LGPL are applicable instead
12   * of those above. If you wish to allow use of your version of this file only
13   * under the terms of the LGPL, and not to allow others to use your version of
14   * this file under the terms of the EPL, indicate your decision by deleting
15   * the provisions above and replace them with the notice and other provisions
16   * required by the LGPL. If you do not delete the provisions above, a recipient
17   * may use your version of this file under the terms of the EPL or the LGPL.
18   *
19   * Based on the original MiniSat specification from:
20   *
21   * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
22   * Sixth International Conference on Theory and Applications of Satisfiability
23   * Testing, LNCS 2919, pp 502-518, 2003.
24   *
25   * See www.minisat.se for the original solver in C++.
26   *
27   * Contributors:
28   *   CRIL - initial API and implementation
29   *******************************************************************************/
30  package org.sat4j.minisat.core;
31  
32  import java.io.PrintWriter;
33  
34  /**
35   * Interface for the variable ordering heuristics. It has both the
36   * responsibility to choose the next variable to branch on and the phase of the
37   * literal (positive or negative one).
38   * 
39   * @author daniel
40   * 
41   */
42  public interface IOrder {
43  
44      /**
45       * Method used to provide an easy access the the solver vocabulary.
46       * 
47       * @param lits
48       *            the vocabulary
49       */
50      void setLits(ILits lits);
51  
52      /**
53       * Selects the next "best" unassigned literal.
54       * 
55       * Note that it means selecting the best variable and the phase to branch on
56       * first.
57       * 
58       * @return an unassigned literal or Lit.UNDEFINED no such literal exists.
59       */
60      int select();
61  
62      /**
63       * Method called when a variable is unassigned.
64       * 
65       * It is useful to add back a variable in the pool of variables to order.
66       * 
67       * @param x
68       *            a variable.
69       */
70      void undo(int x);
71  
72      /**
73       * To be called when the activity of a literal changed.
74       * 
75       * @param p
76       *            a literal. The associated variable will be updated.
77       */
78      void updateVar(int p);
79  
80      /**
81       * that method has the responsibility to initialize all arrays in the
82       * heuristics. PLEASE CALL super.init() IF YOU OVERRIDE THAT METHOD.
83       */
84      void init();
85  
86      /**
87       * Display statistics regarding the heuristics.
88       * 
89       * @param out
90       *            the writer to display the information in
91       * @param prefix
92       *            to be used in front of each newline.
93       */
94      void printStat(PrintWriter out, String prefix);
95  
96      /**
97       * Sets the variable activity decay as a growing factor for the next
98       * variable activity.
99       * 
100      * @param d
101      *            a number bigger than 1 that will increase the activity of the
102      *            variables involved in future conflict. This is similar but
103      *            more efficient than decaying all the activities by a similar
104      *            factor.
105      */
106     void setVarDecay(double d);
107 
108     /**
109      * Decay the variables activities.
110      * 
111      */
112     void varDecayActivity();
113 
114     /**
115      * To obtain the current activity of a variable.
116      * 
117      * @param p
118      *            a literal
119      * @return the activity of the variable associated to that literal.
120      */
121     double varActivity(int p);
122 
123     /**
124      * indicate that a literal has been satisfied.
125      * 
126      * @param p
127      */
128     void assignLiteral(int p);
129 
130     void setPhaseSelectionStrategy(IPhaseSelectionStrategy strategy);
131 
132     IPhaseSelectionStrategy getPhaseSelectionStrategy();
133 
134     /**
135      * Allow to perform a specific action when a literal of the current decision
136      * level is updated. That method is called after {@link #updateVar(int)}.
137      * 
138      * @param q
139      *            a literal
140      */
141     void updateVarAtDecisionLevel(int q);
142 
143     /**
144      * Read-Only access to the value of the heuristics for each variable. Note
145      * that for efficiency reason, the real array storing the value of the
146      * heuristics is returned. DO NOT CHANGE THE VALUES IN THAT ARRAY.
147      * 
148      * @return the value of the heuristics for each variable (using Dimacs
149      *         index).
150      * @since 2.3.2
151      */
152     double[] getVariableHeuristics();
153 }