package yacs.solver.fdsolver.consistency;

import yacs.domain.*;
import yacs.parser.*;

import java.util.*;

/**
 * <p>Hilfsklasse zur Beschreibung einer "Kante" für binäre Algorithmen zur
 * Herstellung von Kantenkonsistenz. Eine Kante zwischen zwei Knoten entspricht
 * einem binären Constraint, welches zwei Constraint-Variablen beschränkt.</p>
 *
 * <p>Copyright (C) 2005  Wolfgang Runte
 * <br><br>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <br><br>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * <br><br>
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA</p>
 *
 * @author Wolfgang Runte (woru@tzi.org)
 * @version YACS 0.1.1
 */
public class BinaryArc extends HyperArc {

// ********** private attributs **********

  /** Startknoten der Kante. */
  private final String startNode;

  /** Endknoten der Kante. */
  private final String endNode;

// ********** public attributs **********

// ********** private methods **********

// ********** public methods **********

  /**
   * Konstruktor -- Benötigt den Start- und Endknoten der Kante sowie den
   * Constraint-Ausdruck, der diese Kante beinhaltet.
   */
  public BinaryArc(String startNode, String endNode, Expression expr) {
    this.startNode = startNode;
    this.endNode = endNode;
    this.expr = expr;
    // Die "nodesMap" initialisieren (in der übergeordneten Klasse):
    LinkedList nodes = new LinkedList();
    nodes.add(startNode);
    nodes.add(endNode);
    this.nodesMap = this.initNodesMap(nodes, this.expr);
  }

  /**
   * Liefert den Startknoten der Kante.
   * @return String
   */
  public String startNode() {
    return this.startNode;
  }

  /**
   * Liefert die Domäne des Startknotens.
   * @return Domain
   */
  public Domain startDomain() {
    return (Domain)super.nodesMap.get(this.startNode);
  }

  /**
   * Liefert den Endknoten der Kanten.
   * @return String
   */
  public String endNode() {
    return this.endNode;
  }

  /**
   * Liefert die Domäne des Endknotens.
   * @return Domain
   */
  public Domain endDomain() {
    return (Domain)this.nodesMap.get(this.endNode);
  }

  /**
   * Liefert die Kante als String (für Debugging).
   * @return String
   */
  public String toString() {
    return this.startNode() + " -> " + this.endNode() + "; Expression: " + this.expr;
  }

}
