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