language: C++ 4.7.2 (gcc-4.7.2)
date: 497 days 9 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <math.h>
 
 
using namespace std;
 
class firefly{
 
private:
 
float threshold;//livello dell'eccitazione
float period;//periodo dell' "oscillazione"
float lin_slope;//pendenza del fronte d'onda, non so se sia necessaria
float x, y;//coordinate 2D della lucciola 
float flash_time; 
float phase;
 
public:
 
firefly(int, int, float, float);
firefly();
firefly(const firefly& a);
 
float get_time();
void receive_flash(std :: vector<firefly>&, float, float, int);
friend bool operator < (const firefly&, const firefly&);
};
 
firefly :: firefly() {}
 
firefly ( const& firefly a ) : lato_x(a.lato_x), lato_y(a.lato_y), threshold(a.threshold), period(a.period), lin_slope(a.lin_slope) 
 
    {
       
       time_flash = ( rand() %(b*1000) ) /1000;
                 
                 x = ( rand() %(lato_x*1000) )/1000;
 
                 y = ( rand() %(lato_y*1000) )/1000;
              
        }
        
        
 
firefly :: firefly (int latoX, int latoY, float max_exc, float periodo) : lato_x(latoX), lato_y(latoY), 
 
threshold(max_exc), period(periodo), lin_slope(max_exc/periodo)
 
     {
 
        
                 time_flash = ( rand() %(b*1000) ) /1000;
                 
                 x = ( rand() %(lato_x*1000) )/1000;
 
                 y = ( rand() %(lato_y*1000) )/1000;
              
               
              
         }
 
 
 
float firefly :: get_time () {return time_flash;}
 
                       
 
firefly :: receive_flash(vector<firefly>* vec, float b, float e, int j) {
 
 
         //alfa e beta servono per calcolare l'incremento della fase phase:
         //phase + delta(phase) = min{ alfa*phase + beta, 1 }
         
         
         float alfa = exp(b*e);
         float beta = (exp(b*e) - 1)/(exp(b) - 1);
         
                
         for (int i = j + 1; i < vec.size(); i++)
                     
                        
                          {
                      
                            vec[j].phase = 0.;
                            
                            vec[j].phase += ( vec[i].time_flash - vec[j].time_flash ) * vec[i].lin_slope;
                            
                            float diff = alfa*phase + beta;
                            
                            float phase_plus_delta_phase = (diff < 1. ? diff : 1.);
                            
                            vec[j].time_flash = vec[i].time_flash;
                            
                            if ( phase_plus_delta_phase == 1.) break;                   
                            
                            };
                                                                      
                                                                                                       
                     }
                     
                     
                     
    bool operator<(const firefly& rhs, const firefly& lhs)
 
      {
      
        float a, b;
        
        a = rhs.get_time(); b = lhs.get_time();
        
        return a < b;
        
        }
        
 
int main() {
 
cout << "Quante Lucciole?\n";
 
int number;
 
cin  >> number;
 
vector <firefly> fire_vec(10, firefly(5, 5,(float) 1., (float)1.) );
 
sort(fire_vec.begin(), fire_vec.end());
 
cout << "How many iterations?\n";
 
int numb_iterations;
 
float beta, epsilon;
 
    cin >> numb_iterations;
 
cout << "Beta?\n";
 
    cin >> beta;
 
cout << "Epsilon\n";
 
    cin >> epsilon;
 
for (int i = 0; i < numb_iteration; i++)
 
     {
           
      for (int j = 0; j < fire_vec.size(); j++)
      
         {
         
           fire_vec[j].receive_flash(fire_vec, beta, epsilon, j);
           
           };
           
      sort(fire_vec.begin(), fire_vec.end());
           
        };
        
      
      
      }//end main()
 
 
 
prog.cpp:34: error: expected unqualified-id before ‘const’
prog.cpp:34: error: expected `)' before ‘const’
prog.cpp: In constructor ‘firefly::firefly(int, int, float, float)’:
prog.cpp:48: error: class ‘firefly’ does not have any field named ‘lato_x’
prog.cpp:48: error: class ‘firefly’ does not have any field named ‘lato_y’
prog.cpp:55: error: ‘time_flash’ was not declared in this scope
prog.cpp:55: error: ‘b’ was not declared in this scope
prog.cpp:57: error: ‘lato_x’ was not declared in this scope
prog.cpp:59: error: ‘lato_y’ was not declared in this scope
prog.cpp: In member function ‘float firefly::get_time()’:
prog.cpp:67: error: ‘time_flash’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:71: error: ISO C++ forbids declaration of ‘receive_flash’ with no type
prog.cpp:71: error: prototype for ‘int firefly::receive_flash(std::vector<firefly, std::allocator<firefly> >*, float, float, int)’ does not match any in class ‘firefly’
prog.cpp:28: error: candidate is: void firefly::receive_flash(std::vector<firefly, std::allocator<firefly> >&, float, float, int)
prog.cpp: In function ‘bool operator<(const firefly&, const firefly&)’:
prog.cpp:112: error: passing ‘const firefly’ as ‘this’ argument of ‘float firefly::get_time()’ discards qualifiers
prog.cpp:112: error: passing ‘const firefly’ as ‘this’ argument of ‘float firefly::get_time()’ discards qualifiers
prog.cpp: In function ‘int main()’:
prog.cpp:147: error: ‘numb_iteration’ was not declared in this scope
prog.cpp:151: warning: comparison between signed and unsigned integer expressions