swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling equations as objects


From: Miles Parker
Subject: Re: Handling equations as objects
Date: Fri, 21 Aug 1998 15:41:20 -0400

[cc'd: to swarm list, as I think others might have interest.]

No, its completely general, the only non-general aspect would be in how you 
used it. Really, it seems you could come up with a whole class hierarchy and 
methodology for diiferent types of functions, but that is far outside of my 
area of knowledge/resources.

A couple of possibilities come to mind:

a) As suggested above, provide a whole set of generalized equations that you 
could plug in. This could be a tremendous amount of work depending on how many 
basic forms there are.

b1) Write and compile just the particular Function subclass (only overiding the 
solveFor method) immediatly before the run, and then give it to the agent 
objects as appropriate. This would actually be very easy to do, and a good 
implementation of the 80/20 rule. Much beter than trying to write your own 
equation parser, and (arguably) better than the overhead of using an 
interpreter, if you can convince your clients to be flexible on this point.

b2) I don't know about Obj C, but in Java it is actually quite possible to 
compile and load at run-time (litttle known fact!), which creates some cool 
dynamic possibilities. That is, you can create a text file that defines a 
subclass of the Function class, for instance, with just a method override of 
solveFor, filled in with the contents of a file (or a text field!) You can then 
actually invoke the javac compiler from the Java vm, compile the file, and then 
load the class dynamically using Class.forName(). Perhaps some similar facility 
is available for Obj C?

-Miles

>>> Jayshree Sarma <address@hidden> 08/21 12:54 PM >>>
Miles,

Thanks for your code.  I have yet to learn Java 
but your code reads just like obj-c code.
Is your Function class code for a particular
form of equation or it is more general that?

The client wants to be able to try different 
equations for the consumer and producers and study
the simulation results.  The equation form is not
know before hand, it may be linear or non linear.
They want to be able to have swarm read in the eqaation
before the start of the simulation and use those
for the current simulation run.  

Jayshree

On Fri, 21 Aug 1998, Miles Parker wrote:

> 
> 
> Miles T. Parker                 mailto:address@hidden 
> Research Software Engineer                            202.797.6136
> The Brookings Institution                   fax 202.797.6319
> 1775 Massachusettes Avenue, N.W., Washington, D.C. 20036
> 
> 
> >>> Jayshree Sarma <address@hidden> 08/21 11:10 AM >>>
> Yes, the functional form of the equation can change.  Also
> the number of terms in the equation can increase/decrease. The
> values of the parameters/coefficients can also change.
> 
> In this case, using my code for context (sorry I'm speaking a different 
> language!), you simply create various subclasses for each functional form, 
> and then instantiate them and assign them to agents or collections of agents 
> as appropriate. It might even be useful to create ready instatiations of 
> these (or even a factory class or method) so that you could simply set the 
> appropriate function for a given agent, but you wouldn't have to instantiate 
> for each agent, e.g.:
> 
> *****
> 
> public class MyAgent {
> 
>     private Function function;
> 
>     public static final FUNCTION_FORM_1 = new FunctionForm1();
> 
>     public static final FUNCTION_FORM_2 = new FunctionForm2();
> 
>    public void setFunction(Function function) {
>        this.function = function;
>    }
> }
> 
> *****
> 
> myAgent.setFunction(Agent.FUNCTION_FORM_1);
> 
> Of course, you would have to change the example significantly to support 
> changing numbers of parameters...you'd might provide setters for everything 
> (perhaps with some mechanism for distinguishing parameters from terms) and 
> some no parameter solve method, OR...better, you might just create a 
> "ParamaterSet" class that would support n dimensions.
> 
> -Miles
> 
> 



                  =================================   Swarm-Support is for 
discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ================================

reply via email to

[Prev in Thread] Current Thread [Next in Thread]