src/java/isac/interfaces/IToCalc.java
author wneuper
Thu, 17 Jan 2008 16:27:03 +0100
changeset 3881 72f0be16d83b
parent 3623 374f1db5f95a
child 3928 d38196e9b162
permissions -rw-r--r--
start-work-070517 merged into HEAD
     1 /**
     2  * @author Alan Krempler
     3  * Created on Sep 19, 2003
     4  */
     5 package isac.interfaces;
     6 
     7 import java.rmi.Remote;
     8 import java.rmi.RemoteException;
     9 
    10 import isac.util.formulae.*;
    11 import isac.util.tactics.*;
    12 
    13 /**
    14  * Interface to be used to communicate in the direction towards the Math Engine.
    15  * 
    16  * @author Alan Krempler WN040924 rename to ICalcTree ?
    17  */
    18 
    19 public interface IToCalc extends Remote {
    20 
    21     /** remove the CalcTree in the math-engine
    22      */
    23     public boolean destruct() throws RemoteException;
    24     
    25     /**
    26      * Get a new iterator referencing the root element of the calculation tree.
    27      * <p>
    28      * The functionality for navigating the calculation is implemented in the
    29      * CalcIterator object.
    30      * 
    31      * @return new instance of CalcIterator
    32      */
    33     public ICalcIterator iterator() throws RemoteException;
    34 
    35     /**
    36      * Register a new listener who wants to be notified of changes in the data.
    37      * The listener has to implement the IToUser interface.
    38      * 
    39      * @param listener
    40      *            New listener to be registered.
    41      * @return false on success, true otherwise.
    42      */
    43     public boolean addDataChangeListener(IToUser listener)
    44             throws RemoteException;
    45 
    46     /**
    47      * @return an iterator referencing the current "hot spot" in the
    48      *         calculation, i.e. the active formula.
    49      */
    50     public ICalcIterator getActiveFormula() throws RemoteException;
    51 
    52     /**
    53      * Makes the passed formula the active formula, i.e. the formula the next
    54      * tactic is applied to.
    55      * 
    56      * @param newActiveFormula
    57      *            Iterator referencing the new desired position
    58      */
    59     public void moveActiveFormula(ICalcIterator newActiveFormula)
    60             throws RemoteException;
    61 
    62     /**
    63      * Set the Descriptions for all ModelItems given by the problem which is
    64      * specified in the CalcHead held in the MathEngine (this may still be
    65      * hidden from the front-end).
    66      * 
    67      * in contrary to isac.interfaces.IToCalc#setNextTactic this method has a
    68      * returnvalue from the calculation.
    69      * 
    70      * @return CalcHead with Descriptions (e.g. equality, solveFor)
    71      * @exception RemoteException
    72      */
    73     public CalcHead modelProblem() throws RemoteException;
    74 
    75     /**
    76      * Add _ONE_ item to the Model or to the Specification, as long as the
    77      * CalcHead is not complete.
    78      * 
    79      * in contrary to the methods for the solve-phase this method returns a
    80      * value from the calculation.
    81      * 
    82      * @return CalcHead with one item added; if the CalcHead was complete, the
    83      *         CalcHead remains unchanged
    84      * @exception RemoteException
    85      */
    86     public CalcHead nextSpecify() throws RemoteException;
    87 
    88     /**
    89      * Check a given CalcHead. The result is the same CalcHead with status flags
    90      * for each item
    91      * 
    92      * in contrary to the methods for the solve-phase this method returns a
    93      * value from the calculation.
    94      * 
    95      * @see CalcHead for possible status flags
    96      * @param calc_head
    97      *            CalcHead to be checked
    98      * @return new CalcHead with a status for each item
    99      */
   100     public CalcHead checkCalcHead(CalcHead calc_head) throws RemoteException;
   101 
   102     /**
   103      * Complete the Model of a CalcHead: Tell the Kernel to fill out all the
   104      * missing fields in the Model; this may not succeed if the (manual) input
   105      * is too messed up (in this case first a resetCalcHead must be done).
   106      * 
   107      * in contrary to the methods for the solve-phase this method returns a
   108      * value from the calculation.
   109      * 
   110      * @return the CalcHead with the completed Model
   111      */
   112     public CalcHead completeModel() throws RemoteException;
   113 
   114     /**
   115      * Transfer the Theory selected in the TheoryBrowser to the SML-kernel. This
   116      * method is used for transferring the Theory to the Worksheet (i.e. the
   117      * CalcHead with the Theory inserted and checked has to be fetched from the
   118      * SML-kernel by the front-end)
   119      * 
   120      * in contrary to the methods for the solve-phase this method returns a
   121      * value from the calculation.
   122      * 
   123      * @param thy_id
   124      *            the identifier of the theory
   125      * @return CalcHead with the Theory inserted; the new Theory may cause parse
   126      *         errors (because parts of a formula are unknown in this Theory)
   127      *         displayed in the Model (or in the guard)
   128      * @exception RemoteException
   129      */
   130     public CalcHead setTheory(String thy_id) throws RemoteException;
   131 
   132     /**
   133      * Transfer the Problem selected in the ProblemBrowser to the SML-kernel.
   134      * This method is used for transferring the Problem to the Worksheet (i.e.
   135      * the CalcHead with the Problem inserted and checked has to be fetched from
   136      * the SML-kernel by the front-end)
   137      * 
   138      * in contrary to the methods for the solve-phase this method returns a
   139      * value from the calculation.
   140      * 
   141      * @return CalcHead with the Problem inserted; the new Problem may cause
   142      *         error-status for some ModelItems already input (because they do
   143      *         not match the Problem selected)
   144      * @exception RemoteException
   145      */
   146     public CalcHead setProblem(ProblemID id) throws RemoteException;
   147 
   148     /**
   149      * Transfer the Method selected in the MethodBrowser to the SML-kernel. This
   150      * method is used for transferring the Method to the Worksheet (i.e. the
   151      * CalcHead with the Method inserted and checked has to be fetched from the
   152      * SML-kernel by the front-end)
   153      * 
   154      * in contrary to the methods for the solve-phase this method returns a
   155      * value from the calculation.
   156      * 
   157      * @return CalcHead with the Method inserted; the new Method may cause
   158      *         error-status for some ModelItems in the guard (because they do
   159      *         not match the Method selected)
   160      * @exception RemoteException
   161      */
   162     public CalcHead setMethod(MethodID id) throws RemoteException;
   163 
   164     /**
   165      * Complete a given CalcHead: Tell the Kernel to fill out all the missing
   166      * fields in the Model _and_ in the Specification; this may not succeed if
   167      * the (manual) input is too messed up (in this case first a resetCalcHead
   168      * must be done).
   169      * 
   170      * in contrary to the methods for the solve-phase this method returns a
   171      * value from the calculation.
   172      * 
   173      * @return the completed CalHead
   174      */
   175     public CalcHead completeCalcHead() throws RemoteException;
   176 
   177     /**
   178      * Reset the CalcHead to the state as it was after startCalculation. This
   179      * may help to escape from a CalcHead with messed input, which may not allow
   180      * for a successful completeCalcHead.
   181      * 
   182      * in contrary to the methods for the solve-phase this method returns a
   183      * value from the calculation.
   184      * 
   185      * @return an empty CalcHead
   186      * @exception RemoteException
   187      */
   188     public CalcHead resetCalcHead() throws RemoteException;
   189 
   190     /**
   191      * Complete a given calc_head_: Tell the Kernel to fill out a missing field
   192      * in the calc_head_, which is specified by an parameter
   193      * 
   194      * in contrary to the methods for the solve-phase this method returns a
   195      * value from the calculation.
   196      * 
   197      * @param calc_head_
   198      *            the calc_head_ to be completed
   199      * @param completeItem
   200      *            the item which should be added TODO: return int like
   201      *            replaceFormula etc. WN040916 don't confuse with
   202      *            autCalculate(...CompleteCalcHead) WN0504 this case is notyet
   203      *            designed: how indicate the field ???
   204      * @return the completed CalHead
   205      */
   206     public CalcHead completeCalcHead(CalcHead calcHead, int completeItem)
   207             throws RemoteException;
   208 
   209     /**
   210      * Tries to replaces the active formula in the calculation tree by the
   211      * passed formula. This could fail if no valid derivation from the preceding
   212      * formula to the (new) active formula can be found.
   213      * <p>
   214      * Parts of the calculation after the replaced formula are likely to become
   215      * invalid, listeners will be informed of this with the update message,
   216      * which contains the last unchanged formula.
   217      * 
   218      * @param newFormula
   219      * @return The method will return 0 on success or a nonzero value indicating
   220      *         the status otherwise.
   221      */
   222     public int replaceFormula(CalcFormula newFormula) throws RemoteException;
   223 
   224     /**
   225      * Tries to append the passed formula after the active formula. This could
   226      * fail if no valid derivation from the preceding formula to the (new)
   227      * active formula can be found. The method will fail as well if the active
   228      * formula is not the last formula in the (sub)calculation. Parts of the
   229      * calculation might become invalid.
   230      * 
   231      * @param newFormula
   232      * @return The method will return 0 on success or a nonzero value indicating
   233      *         the status otherwise.
   234      */
   235     public int appendFormula(CalcFormula newFormula) throws RemoteException;
   236 
   237     /**
   238      * requests the intermediate steps leading to the Formula at the Iterator
   239      * (i.e. these steps might be calculated by the math-engine)
   240      * 
   241      * @param Iterator
   242      * 
   243      * @return transactionID also returned in the CalcChanged
   244      */
   245     public int intermediateSteps(ICalcIterator ic) throws RemoteException;
   246 
   247     /**
   248      * Set the tactic to be used in the next step of calculation.
   249      * 
   250      * @param tactic
   251      *            the Tactic to be used in the the next step
   252      * @return The return value indicates success, failure or probable success
   253      *         at a later time.
   254      */
   255     public int setNextTactic(Tactic tactic) throws RemoteException;
   256 
   257     /**
   258      * Retrieve the tactic proposed by the SML-Kernel for the next step in the
   259      * calculation.
   260      * 
   261      * @return proposed tactic. Can be null, if the kernel does not know what to
   262      *         do next, or if the end of the calculation is reached
   263      */
   264     public Tactic fetchProposedTactic() throws RemoteException;
   265 
   266     /**
   267      * Fetch all tactics applicable to the current situation known to the
   268      * system.
   269      * 
   270      * @see #fetchApplicableTactics(int)
   271      */
   272     public static final int TACTICS_ALL = 1;
   273 
   274     /**
   275      * Fetch all tactics applicable to the current situation, but restrict the
   276      * result to tactics from the current theory.
   277      * 
   278      * @see #fetchApplicableTactics(int)
   279      */
   280     public static final int TACTICS_CURRENT_THEORY = 2;
   281 
   282     /**
   283      * Fetch all tactics applicable to the current situation, but restrict the
   284      * result to tactics from the method being applied.
   285      * 
   286      * @see #fetchApplicableTactics(int)
   287      */
   288     public static final int TACTICS_CURRENT_METHOD = 3;
   289 
   290     //	/**
   291     //	 * Get a list of tactics applicable to the active formula.
   292     //	 *
   293     //	 * @param scope
   294     //	 * The filter parameter selects the scope of search for
   295     //	 * applicable tactics.
   296     //	 * @return Array with applicable tactics
   297     //	 * @see #TACTICS_ALL
   298     //	 * @see #TACTICS_CURRENT_THEORY
   299     //	 * @see #TACTICS_CURRENT_METHOD
   300     //	 */
   301     //	public Tactic[] fetchApplicableTactics(int scope) throws RemoteException;
   302 
   303     /**
   304      * Do the number of steps requested, without any restrictions. autoCalculate
   305      * ... CompleteCalc Do NOT change the value of this constant, as this number
   306      * has a specifig meaning in other parts of the system!
   307      * 
   308      * @see #autoCalculate(int, int)
   309      */
   310     public static final int SCOPE_CALCULATION = 7;
   311 
   312     /**
   313      * Do the number of steps requested, without any restrictions. autoCalculate
   314      * ... CompleteModel Do NOT change the value of this constant, as this
   315      * number has a specifig meaning in other parts of the system!
   316      * 
   317      * @see #autoCalculate(int, int)
   318      */
   319     public static final int SCOPE_MODEL = 6;
   320 
   321     /**
   322      * Do the number of steps requested, but do not leave the current
   323      * subcalculation into a subproblem: CompleteToSubpbl Do NOT change the
   324      * value of this constant, as this number has a specifig meaning in other
   325      * parts of the system!
   326      * 
   327      * @see #autoCalculate(int, int)
   328      */
   329     public static final int SCOPE_SUBCALCULATION = 5;
   330 
   331     /**
   332      * Do the number of steps requested, but do not leave the current
   333      * subproblem: autoCalculate ... CompleteSubpbl Do NOT change the value of
   334      * this constant, as this number has a specifig meaning in other parts of
   335      * the system!
   336      * 
   337      * @see #autoCalculate(int, int)
   338      */
   339     public static final int SCOPE_SUBPROBLEM = 4;
   340 
   341     /**
   342      * Calculate the next n steps starting from the active formula or until the
   343      * specified scope is left, whichever comes first.
   344      * 
   345      * @param scope
   346      *            The scope parameter can have following values:
   347      * @param nSteps
   348      *            Specifies the count of steps to be autocalculated. Passing 0
   349      *            for nSteps will calculate until reaching a final result.
   350      * @return The method returns an unique id to identify the request when
   351      *         notifying about updates in the tree.
   352      * @see #SCOPE_CALCULATION
   353      * @see #SCOPE_SUBCALCULATION
   354      * @see #SCOPE_SUBPROBLEM
   355      */
   356     /*
   357      * WN040624: the above design is desirable, but currently not impl. in the
   358      * math-engine, rather: either steps == 0, then regard SCOPE_* or steps !=
   359      * 0, then SCOPE_* irrelevant !
   360      */
   361     public int autoCalculate(int scope, int nSteps) throws RemoteException;
   362 
   363 }