Package com.hpctoday.fada

Source Code of com.hpctoday.fada.AttachedClauses

package com.hpctoday.fada;

import java.util.ArrayList;
import java.util.List;

import com.hpctoday.fada.integersolver.Solver;
import com.hpctoday.fada.integersolver.SolverFactory;

public class AttachedClauses {
  private LogicalClause knowledge;
  private LogicalClause attached;
  private boolean were_unified;
  private LogicalClause unified_clauses;
  private List<Inequation> valid_unification;

  private void SetKnowledge(LogicalClause __fact) {
    knowledge = __fact;
  }

  private void SetAttached(LogicalClause __attached) {
    attached = __attached;
  }

  private void WereUnified(boolean val) {
    were_unified = val;
  }

  private void SetUnifiedClauses(LogicalClause __unified) {
    unified_clauses = __unified;
  }

  @SuppressWarnings("unused")
  private List<Inequation> GetValidUnificationConstraints() {
    return valid_unification;
  }

  @SuppressWarnings("unused")
  private void SetValidUnificationConstraints(List<Inequation> constraints) {
    valid_unification = constraints;
  }

  private void Initialize() {
    SetKnowledge(null);
    SetAttached(null);
    WereUnified(false);
    SetUnifiedClauses(null);
    valid_unification = new ArrayList<Inequation>();
  }

  private void Set(LogicalClause __fact, LogicalClause __attached) {
    SetKnowledge(__fact);
    SetAttached(__attached);
  }

  private void Set(LogicalClause __fact) {
    SetKnowledge(__fact);
    SetAttached(null);
  }

  public AttachedClauses(LogicalClause __fact, LogicalClause __attached) {
    Initialize();
    Set(__fact, __attached);
  }

  public AttachedClauses(LogicalClause __fact) {
    Initialize();
    Set(__fact);
  }

  public LogicalClause GetKnowledge() {
    return knowledge;
  }

  public LogicalClause GetAttached() {
    return attached;
  }

  public boolean IsAttached() {
    return attached != null;
  }

  public void Attach(LogicalClause __lc) {
    if (IsAttached()) {
      throw new RuntimeException("AttachedClauses::Attach ... clause is already attached");
    }
    SetAttached(__lc);
  }

  public boolean WereUnified() {
    return were_unified;
  }

  public LogicalClause GetUnified() {
    return unified_clauses;
  }

  public void Unify(List<String> __param) {
    if (GetKnowledge() == null || GetAttached() == null) {
      throw new RuntimeException("AttachedClauses::Unify ... FATAL ERROR (bad initialization)");
    }
    if ((GetKnowledge().GetNonAffineInequations().size() > 0) && (GetAttached().GetNonAffineInequations().size() > 0)) {
      SetUnifiedClauses(GetKnowledge().Unify(GetAttached(), __param));
      WereUnified(GetUnified() != null);

      return;
    }
    WereUnified(false);
  }

  @Override
  public String toString() {
    return Print_str();
  }

  public String Print_str() {
    if (!IsAttached())
      return GetKnowledge() + " <<";
    if (IsAttached() && !WereUnified())
      return GetKnowledge() + " ?= " + GetAttached();
    if (IsAttached() && WereUnified())
      return GetKnowledge() + " == " + GetAttached() + " >> " + GetUnified();

    throw new RuntimeException("AttachedClauses::Print_str(void) .....FATAL ERROR(inappropriate case)");
  }

  public void Detach() {
    SetAttached(null);
  }

  public ContextQuast Traduce2ContextQuast(List<List<Inequation>> env, List<String> __param) {
    if (IsAttached()) {
      throw new RuntimeException("AttachedClauses::Traduce2ContextQuast... warning(inappropriate case)");
    }
    return GetKnowledge().TraduceToQuast(env, __param);
  }

  public boolean IsAccurate(List<Inequation> precedence, List<String> param) {
    List<Inequation> all = new ArrayList<Inequation>();
    List<String> all_var = new ArrayList<String>();
    List<String> empty = new ArrayList<String>();
    all.addAll(Global.MergeInequations(precedence, GetKnowledge().GetAffineInequations()));
    all_var.addAll(Global.MergeVariables(param, GetKnowledge().GetVariables()));
    // cout<<"\nAttachedClauses::IsAccurate....\n"<<PrintInequations(&all);

    Solver s = SolverFactory.createSolver();
    s.set(-1, -1, all_var, empty, all);
    all.clear();
    Quast max = s.Max().EliminateRedondantLeaves(true);
    boolean res = false;

    if (max.IsLeaf() && !max.IsEmpty())
      res = true;
    // cout<<" .........."<<res<<"\n";
    return res;
  }
}
TOP

Related Classes of com.hpctoday.fada.AttachedClauses

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.