Skip to content

Commit

Permalink
Style refactoring on relaxation package
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric committed Feb 5, 2016
1 parent d855b91 commit f4ae2a2
Show file tree
Hide file tree
Showing 15 changed files with 1,603 additions and 1,606 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="format" value="^[a-z][a-zA-Z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package fr.uga.pddl4j.heuristics.relaxation;

import java.util.List;

import fr.uga.pddl4j.util.BitOp;
import fr.uga.pddl4j.encoding.CodedProblem;
import fr.uga.pddl4j.util.BitExp;
import fr.uga.pddl4j.util.BitOp;
import fr.uga.pddl4j.util.IntExp;

import java.util.List;

/**
* This abstract class implements the basic methods of all heuristics.
*
Expand All @@ -34,97 +34,98 @@
*/
public abstract class AbstractHeuristic implements Heuristic {

/**
* The goal to reached.
*/
private BitExp goal;

/**
* The list of facts of the relaxed problem.
*/
private List<IntExp> facts;

/**
* The lists of operators of the relaxed problem.
*/
private List<BitOp> operators;

/**
* The boolean flag used to indicate if the heuristic is admissible.
*/
private boolean isAdmissible;

/**
* Create a new heuristic for a specified planning problem. By default the heuristic is
* considered as admissible.
*
* @param problem the problem to solve.
* @throws NullPointerException if <code>problem == null</code>.
*/
protected AbstractHeuristic(final CodedProblem problem) throws NullPointerException {
if (problem == null)
throw new NullPointerException("problem == null");
this.facts = problem.getRevelantFacts();
this.goal = problem.getGoal();
this.operators = problem.getOperators();
this.isAdmissible = true;
}

/**
* Returns <code>true</code> if this heuristic is admissible.
*
* @return <code>true</code> if this heuristic is admissible.
*/
public boolean isAdmissible() {
return this.isAdmissible;
}

/**
* Marks the heuristic as admissible or not.
*
* @param isAdmissible the admissible flag.
*/
protected final void setAdmissible(boolean isAdmissible) {
this.isAdmissible = isAdmissible;
}

/**
* Returns the goal of the relaxed problem to solve in order to compute the heuristic.
*
* @return the goal.
*/
protected final BitExp getGoal() {
return this.goal;
}

/**
* Set the goal of the the relaxed problem to solve in order to compute the heuristic.
*
* @param goal the goal.
* @throws NullPointerException if <code>goal == null</code>.
*/
protected void setGoal(final BitExp goal) throws NullPointerException {
if (!goal.equals(this.goal)) {
this.goal = goal;
}
}

/**
* Returns the relevant facts of the relaxed problem to solve in order to compute the heuristic.
*
* @return the relevant facts.
*/
protected final List<IntExp> getRevelantFacts() {
return this.facts;
}

/**
* Returns the operators of the relaxed problem to solve in order to compute the heuristic.
*
* @return the operators.
*/
protected final List<BitOp> getOperators() {
return this.operators;
}
/**
* The goal to reached.
*/
private BitExp goal;

/**
* The list of facts of the relaxed problem.
*/
private List<IntExp> facts;

/**
* The lists of operators of the relaxed problem.
*/
private List<BitOp> operators;

/**
* The boolean flag used to indicate if the heuristic is admissible.
*/
private boolean isAdmissible;

/**
* Create a new heuristic for a specified planning problem. By default the heuristic is
* considered as admissible.
*
* @param problem the problem to solve.
* @throws NullPointerException if <code>problem == null</code>.
*/
protected AbstractHeuristic(final CodedProblem problem) throws NullPointerException {
if (problem == null) {
throw new NullPointerException("problem == null");
}
this.facts = problem.getRevelantFacts();
this.goal = problem.getGoal();
this.operators = problem.getOperators();
this.isAdmissible = true;
}

/**
* Returns <code>true</code> if this heuristic is admissible.
*
* @return <code>true</code> if this heuristic is admissible.
*/
public boolean isAdmissible() {
return this.isAdmissible;
}

/**
* Marks the heuristic as admissible or not.
*
* @param isAdmissible the admissible flag.
*/
protected final void setAdmissible(boolean isAdmissible) {
this.isAdmissible = isAdmissible;
}

/**
* Returns the goal of the relaxed problem to solve in order to compute the heuristic.
*
* @return the goal.
*/
protected final BitExp getGoal() {
return this.goal;
}

/**
* Set the goal of the the relaxed problem to solve in order to compute the heuristic.
*
* @param goal the goal.
* @throws NullPointerException if <code>goal == null</code>.
*/
protected void setGoal(final BitExp goal) throws NullPointerException {
if (!goal.equals(this.goal)) {
this.goal = goal;
}
}

/**
* Returns the relevant facts of the relaxed problem to solve in order to compute the heuristic.
*
* @return the relevant facts.
*/
protected final List<IntExp> getRevelantFacts() {
return this.facts;
}

/**
* Returns the operators of the relaxed problem to solve in order to compute the heuristic.
*
* @return the operators.
*/
protected final List<BitOp> getOperators() {
return this.operators;
}

}
71 changes: 35 additions & 36 deletions src/main/java/fr/uga/pddl4j/heuristics/relaxation/AdjustedSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with PDDL4J. If not, see <http://www.gnu.org/licenses/>
*/

package fr.uga.pddl4j.heuristics.relaxation;

import fr.uga.pddl4j.encoding.CodedProblem;
Expand All @@ -36,11 +37,11 @@
* <code>lev(p1) <= lev(p2) <= ... <= lev(pn)</code> where <code>lev(p)</code> is the level
* where the proposition <code>p</code> appears for the first time the planning graph. Under the
* assumption that all propositions are independent, we have
*
* </p>
* <pre>
* code(S) := cost(S - p1) + cost(p1)
* </pre>
*
* <p>
* Since <code>lev(p1) <= lev(S - p1)</code>, proposition is possibly achieved before the set
* <code>S - p1</code>. Now, we assume that there are no positive interactions among the
* propositions, but there may be negative interactions. Therefore, upon achieving
Expand All @@ -52,17 +53,17 @@
* <code>S - p1 </code> and achieving <code>p1</code> (because the planning graph has to expand
* up to <code>lev(S)</code> to achieve both <code>S - p1</code> and <code>p1</code>). To
* take this negative interaction into account, we assign:
*
* </p>
* <pre>
* cost(S) := cost(S - p1) + cost(p1) + (lev(S) - lev(S - p1))
* </pre>
*
* </p>
* Applying this formula to <code>S - p1, S - p1 - p2</code> and so one, we derive:
*
* <p>
* <pre>
* cost(S) := sum(cost(pi) + lev(S) - lev(pn) for all pi in S.
* </pre>
*
* </p>
* Note that <code>lev(pn) = max(lev(pi))</code> for all <code>pi</code> in <code>S</code> as
* per our setup. Thus the estimate above is composed of the sum heuristic function
* <code>hsum = sum(cost(pi))</code> for all <code>pi</code> in <code>S</code> and an
Expand All @@ -75,52 +76,50 @@
* <pre>
* delta(S) := lev(S) - max(lev(p)) for all p in S.
* </pre>
*
* </p>
* It should be noted that the notion of binary interaction degree is only a special case of the
* above definition for a set of two propositions. In addition, when there is no negative
* interaction among subgoals, <code>delta(S) = 0</code>, as expected. We have the following
* heuristic:
*
* <p>
* <pre>
* hadjsum(S) := sum(cost(pi)) + delta(S) or all pi in S.
* </pre>
*
* </p>
* <b>Warning:</b> The adjusted sum heuristic is not admissible.
*
* @author D. Pellier
* @version 1.0 - 10.06.2010
*
* @see Sum
* @see Max
*/
public final class AdjustedSum extends RelaxedGraphHeuristic {

/**
* Creates a new <code>AdjustedSum</code> heuristic for a specified planning problem.
*
* @param problem the planning problem.
* @throws NullPointerException if <code>problem == null</code>.
*/
public AdjustedSum(CodedProblem problem) {
super(problem);
super.setAdmissible(false);
}
/**
* Creates a new <code>AdjustedSum</code> heuristic for a specified planning problem.
*
* @param problem the planning problem.
* @throws NullPointerException if <code>problem == null</code>.
*/
public AdjustedSum(CodedProblem problem) {
super(problem);
super.setAdmissible(false);
}

/**
* Return the estimated distance to the goal to reach the specified state. If the return value is
* <code>Integer.MAX_VALUE</code>, it means that the goal is unreachable from the specified
* state.
*
* @param state the state from which the distance to the goal must be estimated.
* @param goal the goal expression.
* @return the distance to the goal state from the specified state.
* @throws NullPointerException if <code>state == null && goal == null</code>.
*/
public int estimate(final BitState state, final BitExp goal) throws NullPointerException {
super.setGoal(goal);
final int level = super.expandRelaxedPlanningGraph(state);
return super.isGoalReachable() ?
super.getSumValue() + (level - super.getMaxValue()) : Integer.MAX_VALUE;
}
/**
* Return the estimated distance to the goal to reach the specified state. If the return value is
* <code>Integer.MAX_VALUE</code>, it means that the goal is unreachable from the specified
* state.
*
* @param state the state from which the distance to the goal must be estimated.
* @param goal the goal expression.
* @return the distance to the goal state from the specified state.
* @throws NullPointerException if <code>state == null && goal == null</code>.
*/
public int estimate(final BitState state, final BitExp goal) throws NullPointerException {
super.setGoal(goal);
final int level = super.expandRelaxedPlanningGraph(state);
return super.isGoalReachable() ? super.getSumValue() + (level - super.getMaxValue()) : Integer.MAX_VALUE;
}

}
Loading

0 comments on commit f4ae2a2

Please sign in to comment.