01: /*
02: * SamplingThread.java
03: *
04: * Created on 25 maj 2007, 19:54
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package jaimoves.util;
11:
12: import jaimoves.actor.Actor;
13: import jaimoves.jaisimulation;
14: import jaimoves.util.SamplingTask;
15:
16: import java.util.Timer;
17: import java.util.TimerTask;
18:
19: import com.jme.math.Vector3f;
20:
21: /**
22: * samplingThread = new Thread(new Runnable() {
23: * // sampler.schedule(new SamplingTask(this) , 1000,1*1000 );
24: *
25: * });
26: * @author romek
27: */
28: public class SamplingThread extends Thread {
29:
30: private jaisimulation symulacja;
31: private Timer sampler;
32: private SamplingTask task;
33: private int time;
34:
35: Vector3f currentPos = new Vector3f();
36:
37: /** Creates a new instance of SamplingThread */
38: public SamplingThread(jaisimulation sym, int t) {
39: symulacja = sym;
40: time = t;
41: currentPos = symulacja.getAktor().getCenterOfGravity();
42: symulacja.setLastPos(symulacja.getAktor().getCenterOfGravity());
43: System.out.println(symulacja.getLastPos().toString());
44: // task = new SamplingTask(symulacja);
45: // Timer sampler = new Timer();
46: // sampler.schedule(task, time);
47: }
48:
49: public synchronized void run() {
50: while (true) {
51: try {
52: wait(time);
53: {
54: symulacja.setLastPos(currentPos);
55: currentPos = symulacja.getAktor()
56: .getCenterOfGravity();
57: symulacja.setCurrentPos(currentPos);
58: symulacja.updateProblem();
59: symulacja.updateCurrentAntigen();
60: symulacja.applyControl(); // przesuwa juz o jeden przeciwcialo
61: }
62: if (symulacja.isEndOfCalcCycle()) {
63: symulacja.getControl().algorithmSuppresionStep(5);
64: symulacja.getControl().algorithmKillClonesStep();
65: symulacja.getControl().algorithmCloneStep();
66: // WYKONUJEMY RESZTE ALGORYTMU lacznie z selekcja
67: // klonalna i tak dalej
68:
69: }
70:
71: } catch (InterruptedException ex) {
72: }
73: }
74: }
75:
76: public synchronized void setSymulacja(jaisimulation sym) {
77: symulacja = sym;
78: }
79:
80: public Timer getSampler() {
81: return sampler;
82: }
83:
84: public void setSampler(Timer sampler) {
85: this .sampler = sampler;
86: }
87:
88: public int getTime() {
89: return time;
90: }
91:
92: public void setTime(int time) {
93: this.time = time;
94: }
95: }
|