src/java/isac/util/interfaces/IToCalc.java
author wneuper
Tue, 14 Jun 2005 17:22:50 +0200
changeset 2391 59a60ef2a2c8
parent 2306 7192b950c985
child 2437 634301730dc6
permissions -rw-r--r--
java: minor changes preparing tryMatch
     1 /*
     2  * Created on Sep 19, 2003
     3  */
     4 package isac.util.interfaces;
     5 
     6 import java.rmi.Remote;
     7 import java.rmi.RemoteException;
     8 import java.util.Vector;
     9 
    10 import isac.bridge.CalcTree;
    11 import isac.util.Formalization;
    12 import isac.util.NotInSpecificationPhaseException;
    13 import isac.util.formulae.*;
    14 import isac.util.tactics.*;
    15 
    16 /**
    17  * Interface to be used to communicate in the direction towards the Math Engine.
    18  * 
    19  * @author Alan Krempler WN040924 rename to ICalcTree ?
    20  */
    21 
    22 public interface IToCalc extends Remote {
    23 
    24     /**
    25      * Get a new iterator referencing the root element of the calculation tree.
    26      * <p>
    27      * The functionality for navigating the calculation is implemented in the
    28      * CalcIterator object.
    29      * 
    30      * @return new instance of CalcIterator
    31      */
    32     public ICalcIterator iterator() throws RemoteException;
    33 
    34     /**
    35      * Register a new listener who wants to be notified of changes in the data.
    36      * The listener has to implement the IToUser interface.
    37      * 
    38      * @param listener
    39      *            New listener to be registered.
    40      * @return false on success, true otherwise.
    41      */
    42     public boolean addDataChangeListener(IToUser listener)
    43             throws RemoteException;
    44 
    45     /**
    46      * @return an iterator referencing the current "hot spot" in the
    47      *         calculation, i.e. the active formula.
    48      */
    49     public ICalcIterator getActiveFormula() throws RemoteException;
    50 
    51     /**
    52      * Makes the passed formula the active formula, i.e. the formula the next
    53      * tactic is applied to.
    54      * 
    55      * @param newActiveFormula
    56      *            Iterator referencing the new desired position
    57      */
    58     public void moveActiveFormula(ICalcIterator newActiveFormula)
    59             throws RemoteException;
    60 
    61     //	/**
    62     //	 * Start the a calculation by providing initial values to the Dialog On
    63     //	 * success, the Dialog is in DIALOGPHASE_SOLVE
    64     //	 *
    65     //	 * @param user_id
    66     //	 * The user
    67     //	 * @param f
    68     //	 * Formalization from the example collection or null
    69     //	 * @param started_from
    70     //	 * STARTFROM_*
    71     //	 * @return @throws
    72     //	 * RemoteException
    73     //	 *
    74     //	 * @see isac.util.Formalization
    75     //	 */
    76     //	public CalcTree startCalculation(int user_id, Formalization f,
    77     //			int started_from/* , int requested_calchead_view */)
    78     //			throws RemoteException;
    79 
    80     //	/**
    81     //	 * Enter the solving phase of the calculation. StartSpecifying must be
    82     //	 * called first Only possible with a complete and correct calcHead
    83     //	 *
    84     //	 * @param calcHead
    85     //	 * CalcHead for this calculation
    86     //	 * @return CalcTree represents the calculation on the java side
    87     //	 */
    88     //	public void startSolving(/* CalcHead calcHead */) throws Exception;
    89 
    90     /**
    91      * Modify a given CalcHead The result is the same CalcHead with status flags
    92      * for each item
    93      * 
    94      * @see CalcHead for possible status flags
    95      * @param calcHead
    96      *            CalcHead to be modified
    97      * @return new CalcHead with a status for each item TODO: return int like
    98      *         replaceFormula etc.
    99      */
   100     public void modifyCalcHead(CalcHead calcHead) throws RemoteException;
   101 
   102     /**
   103      * Complete a given calcHead: Tell the Kernel to fill out all the missing
   104      * fields in the calcHead
   105      * 
   106      * @param calcHead
   107      *            the calcHead to be completed TODO: return int like
   108      *            replaceFormula etc.
   109      */
   110     public void completeCalcHead() throws RemoteException;
   111 
   112     /**
   113      * Complete a given calcHead: Tell the Kernel to fill out a missing field in
   114      * the calcHead, which is specified by an parameter
   115      * 
   116      * @param calcHead
   117      *            the calcHead to be completed
   118      * @param completeItem
   119      *            the item which should be added TODO: return int like
   120      *            replaceFormula etc.
   121      * 
   122      * WN040916 don't confuse with autCalculate(...CompleteCalcHead) WN0504 this
   123      * case is notyet designed: how indicate the field ???
   124      */
   125     public void completeCalcHead(CalcHead calcHead, int completeItem)
   126             throws RemoteException;
   127 
   128     /**
   129      * Tries to replaces the active formula in the calculation tree by the
   130      * passed formula. This could fail if no valid derivation from the preceding
   131      * formula to the (new) active formula can be found.
   132      * <p>
   133      * Parts of the calculation after the replaced formula are likely to become
   134      * invalid, listeners will be informed of this with the update message,
   135      * which contains the last unchanged formula.
   136      * 
   137      * @param newFormula
   138      * @return The method will return 0 on success or a nonzero value indicating
   139      *         the status otherwise.
   140      */
   141     public int replaceFormula(CalcFormula newFormula) throws RemoteException;
   142 
   143     /**
   144      * Tries to append the passed formula after the active formula. This could
   145      * fail if no valid derivation from the preceding formula to the (new)
   146      * active formula can be found. The method will fail as well if the active
   147      * formula is not the last formula in the (sub)calculation. Parts of the
   148      * calculation might become invalid.
   149      * 
   150      * @param newFormula
   151      * @return The method will return 0 on success or a nonzero value indicating
   152      *         the status otherwise.
   153      */
   154     public int appendFormula(CalcFormula newFormula) throws RemoteException;
   155 
   156     /**
   157      * requests the intermediate steps leading to the Formula at the Iterator
   158      * (i.e. these steps might be calculated by the math-engine)
   159      * 
   160      * @param Iterator
   161      * 
   162      * @return transactionID also returned in the CalcChangedEvent
   163      */
   164     public int intermediateSteps(ICalcIterator ic) throws RemoteException;
   165 
   166     /**
   167      * Set the tactic to be used in the next step of calculation.
   168      * 
   169      * @param tactic
   170      *            the Tactic to be used in the the next step
   171      * @return The return value indicates success, failure or probable success
   172      *         at a later time.
   173      */
   174     public int setNextTactic(Tactic tactic) throws RemoteException;
   175 
   176     /**
   177      * Retrieve the tactic proposed by the SML-Kernel for the next step in the
   178      * calculation.
   179      * 
   180      * @return proposed tactic. Can be null, if the kernel does not know what to
   181      *         do next, or if the end of the calculation is reached
   182      */
   183     public Tactic fetchProposedTactic() throws RemoteException;
   184 
   185     /**
   186      * Fetch all tactics applicable to the current situation known to the
   187      * system.
   188      * 
   189      * @see #fetchApplicableTactics(int)
   190      */
   191     public static final int TACTICS_ALL = 1;
   192 
   193     /**
   194      * Fetch all tactics applicable to the current situation, but restrict the
   195      * result to tactics from the current theory.
   196      * 
   197      * @see #fetchApplicableTactics(int)
   198      */
   199     public static final int TACTICS_CURRENT_THEORY = 2;
   200 
   201     /**
   202      * Fetch all tactics applicable to the current situation, but restrict the
   203      * result to tactics from the method being applied.
   204      * 
   205      * @see #fetchApplicableTactics(int)
   206      */
   207     public static final int TACTICS_CURRENT_METHOD = 3;
   208 
   209     //	/**
   210     //	 * Get a list of tactics applicable to the active formula.
   211     //	 *
   212     //	 * @param scope
   213     //	 * The filter parameter selects the scope of search for
   214     //	 * applicable tactics.
   215     //	 * @return Array with applicable tactics
   216     //	 * @see #TACTICS_ALL
   217     //	 * @see #TACTICS_CURRENT_THEORY
   218     //	 * @see #TACTICS_CURRENT_METHOD
   219     //	 */
   220     //	public Tactic[] fetchApplicableTactics(int scope) throws RemoteException;
   221 
   222     /**
   223      * Do the number of steps requested, without any restrictions. autoCalculate
   224      * ... CompleteCalc Do NOT change the value of this constant, as this number
   225      * has a specifig meaning in other parts of the system!
   226      * 
   227      * @see #autoCalculate(int, int)
   228      */
   229     public static final int SCOPE_CALCULATION = 6;
   230 
   231     /**
   232      * Do the number of steps requested, but do not leave the current
   233      * subcalculation into a subproblem: CompleteToSubpbl Do NOT change the
   234      * value of this constant, as this number has a specifig meaning in other
   235      * parts of the system!
   236      * 
   237      * @see #autoCalculate(int, int)
   238      */
   239     public static final int SCOPE_SUBCALCULATION = 5;
   240 
   241     /**
   242      * Do the number of steps requested, but do not leave the current
   243      * subproblem: autoCalculate ... CompleteSubpbl Do NOT change the value of
   244      * this constant, as this number has a specifig meaning in other parts of
   245      * the system!
   246      * 
   247      * @see #autoCalculate(int, int)
   248      */
   249     public static final int SCOPE_SUBPROBLEM = 4;
   250 
   251     /**
   252      * Calculate the next n steps starting from the active formula or until the
   253      * specified scope is left, whichever comes first.
   254      * 
   255      * @param scope
   256      *            The scope parameter can have following values:
   257      * @param nSteps
   258      *            Specifies the count of steps to be autocalculated. Passing 0
   259      *            for nSteps will calculate until reaching a final result.
   260      * @return The method returns an unique id to identify the request when
   261      *         notifying about updates in the tree.
   262      * @see #SCOPE_CALCULATION
   263      * @see #SCOPE_SUBCALCULATION
   264      * @see #SCOPE_SUBPROBLEM
   265      */
   266     /*
   267      * WN040624: the above design is desirable, but currently not impl., rather:
   268      * either steps == 0, then regard SCOPE_* or steps != 0, then SCOPE_*
   269      * irrelevant !
   270      */
   271     public int autoCalculate(int scope, int nSteps) throws RemoteException;
   272 
   273     /**
   274      * get the Formulae and CalcHeads of the calcTree between the two iterators
   275      * (including the elements the two iterators a pointing to)
   276      * 
   277      * @param iterator_from
   278      *            The iterator pointing to the element immediately before of the
   279      *            returned range (which supports direct use of ...
   280      * @see isac.util.CalcChangedEvent.last_unchanged_formula_
   281      * @param iterator_to
   282      *            The iterator pointing at the last element of the returned
   283      *            range
   284      * @param level
   285      *            The maximum level of the elements in the range, element with a
   286      *            higher level (who are "deeper" in the hierarchie are not
   287      *            returned null if everything should be displayed
   288      * @param result_includes_tactics
   289      *            true if the result should include the tactics, false otherwise
   290      * 
   291      * @return an Vector containing the Formulae and CalcHeads of the calcTree
   292      * @author Alois Kirchsteiger 12.01.2005 16:51:43
   293      */
   294     public Vector getElementsFromTo(ICalcIterator iterator_from,
   295             ICalcIterator iterator_to, Integer level,
   296             boolean result_includes_tactics) throws RemoteException;
   297 
   298 	/**
   299 	 * Match a given problem for this CalcTree
   300 	 * 
   301 	 * @param problemID
   302 	 * @param CalcHead FIXXXME.WN050610 drop !!!
   303 	 * 
   304 	 * @return CalcHead, if the operation was successful, else null
   305 	 * ... replaced by ref-arg to be used instead
   306 	 */
   307 	public void tryMatch(CalcHead calcHead, CalcHeadCompoundID problemID)
   308 			throws NotInSpecificationPhaseException;
   309 
   310 }