RepairCandidate.java
Go to the documentation of this file.
00001 /*
00002  * (c) copyright 2008, Technische Universitaet Graz and Technische Universitaet Wien
00003  *
00004  * This file is part of jdiagengine.
00005  *
00006  * jdiagengine is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * jdiagengine is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with jdiagengine. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Authors: Joerg Weber, Franz Wotawa
00019  * Contact: jweber@ist.tugraz.at (preferred), or fwotawa@ist.tugraz.at
00020  *
00021  */
00022 
00023 
00024 package dfengine;
00025 
00026 import java.util.*;
00027 
00028 import utils.*;
00029 
00030 public class RepairCandidate  {
00031 
00032     protected RepairOrderDAG order;
00033 
00034 
00035     public RepairCandidate(ModeAssignment ma) {
00036         order = new RepairOrderDAG(ma);
00037     }
00038 
00039     public int size() {
00040         return order.getNumNodes();
00041     }
00042 
00043     public String toString() {
00044         return order.toString();
00045     }
00046 
00047     boolean equalComponents(ModeAssignment ma) {
00048         
00049         if (ma.size() != order.getNumNodes()) return false;
00050         else {
00051             return order.equalComponents(ma.getComponents());
00052         }
00053 
00054     }
00055 
00056     /*
00057      * Returns true iff the ordering of components in this candidate
00058      * implies the ordering of components in ma.
00059      * In other words: iff the order in this candidate is equal to or stronger
00060      * than the order in ma.
00061      *
00062      * Complexity: provided that the transitive closure of this candidate is already computed:
00063      *   O( (log m)^2 * m )  [m...number of modes in ma]
00064      */
00065     boolean impliesOrderOf(ModeAssignment ma) {
00066         
00067         // precondition
00068         assert(equalComponents(ma));
00069 
00070         boolean result = true;
00071 
00072         // iterate through edges in ma, for each edge c_i -> c_j:
00073         // if c_i is not an ancestor of c_j in this candidate, then
00074         // return false
00075 
00076         Iterator itDFModes = ma.getModeIterator(Mode.MODE_DF);
00077         while (itDFModes.hasNext() && result) {  // O(m)
00078             Mode dfMode = (Mode)itDFModes.next();
00079             Component comp = dfMode.component;
00080             Component parent = dfMode.parent;
00081 
00082             RepairOrderDAGNode n_comp = order.getNode(comp);  // O(log m)
00083             RepairOrderDAGNode n_parent = order.getNode(parent);  // O(log m)
00084             GraphMatrix transClosure = order.getTransitiveClosure();
00085             if (!order.isAncestor(n_parent, n_comp, transClosure)) result = false;
00086         }
00087 
00088         return result;
00089     }
00090 
00091     void mergeWith(ModeAssignment ma) {
00092         
00093         System.out.println("MERGE: " + order + "  WITH " + ma.toStringShort());
00094 
00095         // precondition
00096         assert(equalComponents(ma));
00097 
00098         Iterator itDFModes = ma.getModeIterator(Mode.MODE_DF);
00099         while (itDFModes.hasNext()) {
00100             Mode dfMode = (Mode)itDFModes.next();
00101             Component comp = dfMode.component;
00102             Component parent = dfMode.parent;
00103 
00104             if (!order.hasEdge(parent, comp)) {
00105                 order.addEdge(parent, comp);
00106             }   
00107         }
00108 
00109         System.out.println("MERGE results in: " + order);
00110 
00111         // postcondition
00112         assert(impliesOrderOf(ma));
00113     }
00114 
00115 }


tug_ist_diagnosis_engine
Author(s): Safdar Zaman, Gerald Steinbauer
autogenerated on Mon Jan 6 2014 11:51:16