Cybernetics Wiki
Advertisement

Класс v_StaticWeightedSum_va[]

 1 /**
 2  * Combine an array of embedded schemas using
 3  * static weights set at configuration time.
 4  * Configuration is done by setting the values of the embedded[]
 5  * and weights[] arrays.
 6  * (c)1997, 1998 Tucker Balch
 7  */
 8 
 9 package EDU.gatech.cc.is.clay;
10 
11 import java.lang.*;
12 import EDU.gatech.cc.is.util.Vec2;
13 import EDU.gatech.cc.is.util.Units;
14 
15 
16 public class v_StaticWeightedSum_va extends NodeVec2
17 {
18 	/**
19 	Turn debug printing on or off.
20 	*/
21 	public static final boolean DEBUG = /*true;*/Node.DEBUG;
22 	
23 	/**
24 	Maximum number of components of an v_StaticWeightedSum_va node.
25 	*/
26 	public static final int MAX_COMPONENTS = 20;
27 
28 	/**
29 	The embedded nodes to multiply by the weights and sum.
30 	*/
31 	public NodeVec2[]	embedded = new NodeVec2[MAX_COMPONENTS];
32 
33 	/**
34 	The weights to multiply the nodes by.
35 	*/
36 	public double[]		weights  = new double[MAX_COMPONENTS];
37 
38 	/**
39 	Instantiate a v_StaticWeightedSum_va node.
40 	*/
41 	public v_StaticWeightedSum_va()
42 	{
43 	}
44 
45 
46 	Vec2	last_val = new Vec2();
47 	long	lasttime = 0;
48 	/**
49 	Return a Vec2 representing the weighted sum of the embedded
50 	nodes.
51 	@param timestamp long, only get new information if timestamp > than last call
52                 or timestamp == -1.
53 	@return the vector weighted sum.
54 	*/
55 	public Vec2 Value(long timestamp)
56 	{
57                 if (DEBUG) System.out.println("v_StaticWeightedSum_va: Value()");
58  
59                 if ((timestamp > lasttime)||(timestamp == -1))
60                 {
61                         /*--- reset the timestamp ---*/
62                         if (timestamp > 0) lasttime = timestamp;
63  
64                         /*--- add in the weighted value of each schema ---*/
65                         last_val.setr(0);
66 			Vec2 temp;
67 			int i = 0;
68 			while(embedded[i]!=null)
69 			{
70                 		if (DEBUG) System.out.println(i + " weight " + weights[i]);
71 				temp = embedded[i].Value(timestamp);
72 				temp.setr(temp.r * weights[i]);
73 				last_val.add(temp);
74 				i++;
75 			}
76 		}
77 
78 		return (new Vec2(last_val.x, last_val.y));
79 	}
80 }
Advertisement