Monday, August 11, 2008

How fuel changes

Fuel decreasing sample starts to run:




Fuel tank collisions, refuelling sample:




Fuel is blinking RED sample:



Links (some in Italian)

Links:

http://blog.cartaematita.com/temperamente/2008/02/come-api-al-miele-la-teoria-de.htm

http://www.swarm.org/index.php/Main_Page

http://it.wikipedia.org/wiki/Intelligenza_collettiva

Why dynamic parameters ?

It is correct to explain.

A thread running an algorithm to change a value can be whatever in the context of a mechanical (only ?) system simulation. It is feasible to imagine fuel, decreasing, in a "threaded" autonomous way, while time passes, with a define model of variation. With the code done, and the interface foreseeing the capability to receive a "set" of the parameter name (that's the parameter nature of course, eg: fuel), it can be reused. The observer/observable double mutual pattern, collision with fuel tanks can be notified to the parameter thread, and fuel increased. Thus establishing a relation between the value, changing by itself, and what happens in the virtual environment. Every new parameter, with its own meaning add more virtual devices and multiplicity to the simulation scenario, increasing the number of data types.

A virtual parameter with a thread in its soul, to simulate a new range of virtual sensors, based on the changing of a value, like fuel

It is intersting actually, two observer/observable patterns, one against the other, to monitor the ongoing value of a ... value ! That simply thanks to a thread and to the common pattern of the earth beat, to decrease or increase with the time, in its own process, with different color levels, a named floating value. This could be fule, for example, or engine oil. It is self sufficient, not needing nothjing more than jdk runtime, and it is so easy that the few classes involved in this game are posted here to let playing everyone who likes:



Parameters threshold for colors:
it.free.i.virtual.machine.hal.devicealias.laboratory.simulator.dynamicparameter.Levels



DynamicParameter factory (actually only the DEcreasing impl is available):
it.free.i.virtual.machine.hal.devicealias.laboratory.simulator.dynamicparameter.
DynamicParameterFactory




Paradigm interface for this entity:
it.free.i.virtual.machine.hal.devicealias.laboratory.simulator.dynamicparameter.
DynamicParameter




The decreasing (and the only written up to now) impl:
it.free.i.virtual.machine.hal.devicealias.laboratory.simulator.dynamicparameter.
DynamicParameterDecreasingImpl






To try just use these lines of test class:

import java.util.Observable;
import java.util.Observer;
import it.free.i.virtual.machine.hal.devicealias.laboratory.simulator.dynamicparameter.*;

public class Prova extends Observable implements Observer{
public Prova(){
init();
}
private void init(){
long hearBeatYeldPause = 1000;
DynamicParameter dynamicParameterDecresingImpl = new DynamicParameterDecreasingImpl(this);
dynamicParameterDecresingImpl.setHeartBeat(100, hearBeatYeldPause);
dynamicParameterDecresingImpl.setParameterName("Fuel");
super.addObserver(dynamicParameterDecresingImpl);
Thread daemonThread = new Thread(dynamicParameterDecresingImpl);
daemonThread.start();
try {
Thread.sleep(110000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i =0; i < 102; i++){
try{
super.setChanged();
super.notifyObservers();
Thread.sleep(hearBeatYeldPause/2);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
Prova prova = new Prova();
}
@Override
public void update(Observable observable, Object arg1) {
System.out.println("UPDATE RECEIVED by " + observable.toString() + "");
}
}