Monday, February 21, 2011

Simple Object Model - Bottom up Cell Life Demo

- The system is slightly interesting. You can monitor the balance with the number of live cells.
You may notice a shift in mutations as cells grow away from the center.

- With only a few mutations, the color of cells tend to shift in color over time.

- It takes many iterations for emergent behavior to emerge.

- Code wise not really that interesting but already we can visualize the emergent behavior.

- Cheating to make the simulation feasible












Code


trait LivingEntityCell {
def getName : String
def getDNA : DNA
def alive : Boolean
def processDNA() : Unit
def produceProteins() : Unit
def onStepSimulationProcessCell() : Unit
def getMutableSize : Int
def setImmutableSystemTraits : Unit
def onStepSetSystemTraits : Unit
/**
* Metabolic reaction and process to convert energy.
* In our system, amount of energy for this cell.
*/
def getCellularRespirationEnergyLevel : Double
def hasConsumeForReplication : Boolean
/**
* If child available, consume and add to core list.
*/
def consumeChildCellReplication : LivingEntityCell
def onInitializeReplicate(cell:LivingEntityCell) : Unit
def mutateDNAOnReplication(targetCell:LivingEntityCell) : DNA
}



Resources

http://code.google.com/p/ainotebook/downloads/list

keywords - ai,intelligence, emergent behavior, evolution, evolution theory, cells, gameoflife, cells, bacteria, dna.

Wednesday, February 16, 2011

onConfigure for Wicket, use for business logic?

I asked this:

here is the best place to put code to initialize the model before a
page renders. I know of five options, but where do you normally put
this type of initialization.

Before a page renders, I want to set the data in my bean/model with
certain attributes that may only be specific to that page.

I think there are five options.

1. Add initialization logic in the constructor. This may work, but I
don't know if the constructor is called for every page call (E.g. when
the page is deserialized)
2. Add init logic in onBeforeRender. This works and it called for every
request? But is it the best place?
3. Add init logic in a "load" or "getmodel" method in
LoadableDetachableModel class?
4. Add init in previous page on onSubmit method or onEvent. (onSubmit()
{ initBeanInSession(); setResponsePage(); }
5. Pass a model to a panel or page constructor (using pageparameters?)

Are any of these best practices or preferred over the other.

(a) Page Constructor code with Loadable detachable model:

MyPage.java:
...
final Form form = new Form(FORM, new
CompoundPropertyModel(new LoadableDetachableModel() {

private static final long serialVersionUID = 1L;
@Override
protected MyBean load() {
final MyBean app = (MyBean) Session.get().getApp();

?????????????
?????????????
initialize here???????
?????????????
return app;
}
};
});

???
onBeforeRender() {
?? Add initiailize here
final MyBean app = (MyBean) Session.get().getApp();
app.setData(doSomeBusinessLogicHere)

}

or initModel?

/**
* Called once per request on components before they are about to be rendered.
* This method should be used to configure such things as visibility and enabled flags.
*/
@Override
protected void onConfigure() {
super.onConfigure();

// Call business logic and properly set email address.

}

Sunday, February 13, 2011

Constructors in Scala


class R(n: Int, d: Int) {
val (x, y) = {
val g = myfunc
(n/g, d/g)
}
}

class R private (val x: Int, val y: Int);

object R {
def apply(n: Int, d: Int): R = {
val g = myfunc;
new R(n / g, d / g);
}
}

Saturday, February 12, 2011

More on getters and setters - Don't do it

"It's a 25-year-old principle of object-oriented (OO) design that you shouldn't expose an object's implementation to any other classes in the program. The program is unnecessarily difficult to maintain when you expose implementation, primarily because changing an object that exposes its implementation mandates changes to all the classes that use the object." -- By Allen Holub, JavaWorld.com, 01/02/04

To that, don't use setters and getters exclusively for all POJO beans.

http://www.javaworld.com/javaworld/jw-01-2004/jw-0102-toolbox.html

Bottom-Up Artificial Life Demo Update

Here are some of the key features of the artificial life demo:

1. Must have a strong focus on environment - E.g. Sun, Food, Smell, Water, Other Cells
2. Cell Functions, responding to the environment - Movement, etc
3. Attributes that affect functions - Size
4. Mutations

Friday, February 11, 2011

JVMNotebook - Javap output in a web environment



Javap - Use custom Javap source to disassemble Java classes. Use this to check the version of running code or other such functions.

http://code.google.com/p/jvmnotebook/wiki/JavapDisassembleOnWeb

JVMNotebook on Google Code

The Java Virtual Machine ( Sun's JVM is called HotSpot ) is a java bytecode interpreter which is fast, portable and secure. Jython, JRuby, Scala, ABCL (Common Lisp) are popular language implementations that run on the JVM that allow for the jvmcookbook sugar of their particular languages.

keywords: java, general java, j2ee, clojure, scala, abcl, jruby, gwt, apache wicket, spring

This project contains multiple sub-projects and code demos related to those jvm language implementations.

http://code.google.com/p/jvmnotebook/

-- Berlin Brown