Subversion Repositories PlanixRsrch.SVN

Rev

Rev 289 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 7u83 1
 
2
#include "unit.h"
3
#include "qube.h"
4
 
474 7u83 5
#include <cstdio>
45 7u83 6
 
7
/**
8
 * @brief Fire the unit
9
 * @param q the qube this unit belongs to
10
 * @param me
11
 */
12
void unit::fire ( qube * q, int me, float val )
13
{
14
 
15
    int qx, qy, qz;
16
    n_to_xyz ( me, qx, qy, qz, QUBE_DIM );
17
 
18
    printf("Firing: %f from %d\n",val,me);
19
 
20
    for ( int i = 0; i < SYNS_PER_UNIT; i++ ) {
21
        int sx, sy, sz;
22
        n_to_xyz ( i, sx, sy, sz, SYN_DIM );
23
 
24
 
25
        int dx, dy, dz;
26
        dx = qx + sx - SYN_DIM / 2;
27
        dy = qy + sy - SYN_DIM / 2;
28
        dz = qz + sz - SYN_DIM / 2;
29
 
30
        q->fire_hub ( i, dx, dy, dz, val );
31
 
32
    }
33
 
34
}
35
 
36
 
37
 
38
/**
39
 * @brief
40
 * @param qube Qube
41
 * @return
42
 */
43
int unit::run ( class qube * qube, int me )
44
{
45
    int ret;
46
    float fsum = 0;
47
 
48
    mtx.lock();
49
 
50
    if ( sum > 0.7 ) {
51
        fsum = sum;
52
        sum = 0;
53
//        printf("%f\n",sum);
54
        adjust ( 0 );
55
        ret = 1;
56
 
57
    } else {
58
        ret =   0;
59
 
60
    }
61
 
62
    mtx.unlock();
63
 
64
    if ( fsum )
65
        fire ( qube, me, fsum );
66
 
67
    return ret;
68
}
69
 
70
 
71
 
72
 
73
/**
74
 * @brief Funtion to receive an impulse
75
 * @param from From where thim impulse comes
76
 * @param val Value
77
 */
78
void unit::receive ( int from, float val )
79
{
80
    mtx.lock();
81
 
82
    weight_t w = syns[from];
83
    sum += w * val;
84
 
85
    syns[from] = w + ( 1.0 - w ) / ( WSTEP * val ) * 2;
86
 //   adjust ( 0 );
87
    mtx.unlock();
88
}
89
 
90
 
91
 
92
 
93
/**
94
 * @brief
95
 * @param from
96
 */
97
void unit::adjust ( int from )
98
{
99
    for ( int i = 0; i < SYNS_PER_UNIT; i++ ) {
100
        weight_t w = syns[i];
101
        syns[i] = w - w / WSTEP;
102
 
103
        /*		if (i==from){
104
        			val = (1.0-val)/10000.0+val;
105
        		}
106
        		else{
107
        			val = val - val/10000.0;
108
        		}
109
        		syns[i]=val;
110
        */
111
    }
112
}