Commit fd29bb70 authored by Sergey Kireev's avatar Sergey Kireev
Browse files

nle_cpp language fix

parent efa8e865
......@@ -71,8 +71,8 @@ class Neighborhood_base {
int opposite(int dir) const { return (dir+count/2)%count; }
int dx(int dir) { return dx_[dir]; }
int dy(int dir) { return dy_[dir]; }
int dx(int dir) const { return dx_[dir]; }
int dy(int dir) const { return dy_[dir]; }
void fix(int &ix,int &iy,int nx,int ny) const {
while (ix < 0) ix += nx;
......@@ -84,7 +84,7 @@ class Neighborhood_base {
bool isSquare() const { return false; }
bool isHex() const { return false; }
std::string name() { return "hood_base"; }
std::string name() const { return "hood_base"; }
};
template<Neighborhood_type t>
......@@ -98,7 +98,7 @@ class Neighborhood<hood_vonNeumann> : public Neighborhood_base<Neighborhood_valu
public:
Neighborhood():Neighborhood_base<Neighborhood_value<hood_vonNeumann>::ndirs>() {}
bool isSquare() const { return true; }
std::string name() { return "hood_vonNeumann"; }
std::string name() const { return "hood_vonNeumann"; }
};
template<>
......@@ -106,7 +106,7 @@ class Neighborhood<hood_Moore> : public Neighborhood_base<Neighborhood_value<hoo
public:
Neighborhood():Neighborhood_base<Neighborhood_value<hood_Moore>::ndirs>() {}
bool isSquare() const { return true; }
std::string name() { return "hood_Moore"; }
std::string name() const { return "hood_Moore"; }
};
template<>
......@@ -121,7 +121,7 @@ class Neighborhood<hood_hex> : public Neighborhood_base<Neighborhood_value<hood_
}
XY &fix(XY &xy,int nx,int ny) const { fix(xy.x,xy.y,nx,ny); return xy; }
bool isHex() const { return true; }
std::string name() { return "hood_hex"; }
std::string name() const { return "hood_hex"; }
};
struct GroupStatistics {
......@@ -255,10 +255,12 @@ public:
void iterate(int nt);
void iterate();
virtual void rule(int i,int j) {}
virtual void rule(int i,int j) = 0;
std::map<State,int> count() const;
virtual ~CA2D() {}
};
} // namespace ca2d
......
......@@ -40,7 +40,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
bool test_move_NL_dH;
std::stringstream debug_message;
mutable std::stringstream debug_message;
NLE_CA_base(const int nx,const int ny,const int ns = 1):ca(nx,ny),nsize(ns),nnsize(ns*ns),nxsize(1024),groups_found(false),maxgroupsize(0) {
logfn_scc(std::string("NLE_CA_base<")+ca::dirs.name()+std::string(",")+ca::hood.name()+std::string(">"),"int,int,int");
......@@ -161,7 +161,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return true;
}
virtual bool fix_loaded(int base) { exit(-1); return false; }
virtual bool fix_loaded(int base) = 0;
virtual std::array<int,3> neighborhood(const int x,const int y) const {
int count_n = 0;
......@@ -196,7 +196,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return { count_n, count_l, count_e };
}
virtual int count_N_neighbors(int bx,int by) { exit(-1); return 0; }
virtual int count_N_neighbors(int bx,int by) const = 0;
bool try_swap_LE(const int lx,const int ly,const int ex,const int ey) {
//printf("try_swap_LE(%d,%d, %d,%d) : %d\n",lx,ly,ex,ey,ca::hood.count); fflush(stdout);
......@@ -225,10 +225,10 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return ca::rnd01() < exp(-dH/kT);
}
bool may_absorb(int bx,int by) { return is_filled_L(bx,by); }
bool may_desorb(int bx,int by) { return count_N_neighbors(bx,by) < minndes; }
bool may_absorb(int bx,int by) const { return is_filled_L(bx,by); }
bool may_desorb(int bx,int by) const { return count_N_neighbors(bx,by) < minndes; }
double count_dH_move_NL(int bx,int by,int dir) {
double count_dH_move_NL(int bx,int by,int dir) const {
double dH = 0;
for (int i=0;i<st[dir].size();i++) {
int state = ca::getfixd(bx + ctx[dir][i],by + cty[dir][i]);
......@@ -245,13 +245,9 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return dH;
}
virtual std::array<int,3> test_count_nl(int bx,int by,int dir) {
printf("Error: NLE_CA_base<%s,%s>::test_count_nl(%d,%d,%d) is called!\n",ca::dirs.name().c_str(),ca::hood.name().c_str(),bx,by,dir);
exit(-1);
return { 0, 0, 0 };
}
virtual std::array<int,3> test_count_nl(int bx,int by,int dir) const = 0;
double count_dH_move_NL_test(int bx,int by,int dir) {
double count_dH_move_NL_test(int bx,int by,int dir) const {
XY nb(bx,by);
ca::dirs.move(nb,dir);
const auto cnt1 = test_count_nl(bx,by,dir);
......@@ -267,7 +263,8 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return -en*(snn1-snn0)-enl*(snl1-snl0)-el*(sll1-sll0);
}
virtual bool may_move_NL(int bi,int bj,int dir) const { return false; }
virtual bool may_move_NL(int bi,int bj,int dir) const = 0;
bool try_move_NL(int bx,int by,int dir) {
if (test_move_NL_dH) std::stringstream().swap(debug_message);
double dH = count_dH_move_NL(bx,by,dir);
......@@ -283,10 +280,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
if (dH <= 0) return true;
return ca::rnd01() < exp(-dH/kT);
}
virtual void do_move_NL(int bx,int by,int dir) {
printf("Error: NLE_CA_base<%s,%s>::do_move_nl(%d,%d,%d) is called!\n",ca::dirs.name().c_str(),ca::hood.name().c_str(),bx,by,dir);
exit(-1);
}
virtual void do_move_NL(int bx,int by,int dir) = 0;
void find_groups() {
if (groups_found) return;
......@@ -342,12 +336,9 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
return true;
}
virtual void do_move_group_NL(int label,int dir) {
printf("Error: NLE_CA_base<%s,%s>::do_move_group_NL(%d,%d) is called!\n",ca::dirs.name().c_str(),ca::hood.name().c_str(),label,dir);
exit(-1);
}
virtual void do_move_group_NL(int label,int dir) = 0;
virtual void rule(int i,int j) {
void rule(int i,int j) override {
ca::dirs.fix(i,j,ca::nx,ca::ny);
int state = ca::get(i,j);
if (isE(state)) { // E
......@@ -424,7 +415,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
}
}
std::array<int,3> test_count_nle_on_line(int x,int y,int dx,int dy,int n,int initial_state,int final_state) {
std::array<int,3> test_count_nle_on_line(int x,int y,int dx,int dy,int n,int initial_state,int final_state) const {
int count_n = 0;
int count_l = 0;
int count_e = 0;
......@@ -454,7 +445,9 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
}
}
virtual void print_neighbourhood(int bx,int by,int dir) {}
virtual void print_neighbourhood(int bx,int by,int dir) const {}
virtual ~NLE_CA_base() {}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -485,7 +478,9 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
int td[4][6][7]; // test data: x,y,dx,dy,n,first_state,final_state
NLE_sqr_CA(const int nx,const int ny,const int ns = 1) : NLE_CA_base<hood_vonNeumann,hood_type>(nx,ny,ns) { logfn_scc(std::string("NLE_sqr_CA<")+ca::hood.name()+std::string(">"),"int,int,int"); }
NLE_sqr_CA(const int nx,const int ny,const int ns = 1) : NLE_CA_base<hood_vonNeumann,hood_type>(nx,ny,ns) {
logfn_scc(std::string("NLE_sqr_CA<")+ca::hood.name()+std::string(">"),"int,int,int");
}
void setXYS() {
logfn_scc(std::string("NLE_sqr_CA<")+ca::hood.name()+std::string(">"),"");
......@@ -517,7 +512,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
}
}
virtual bool fix_loaded(int base) { // return (i+1) + (j+1)*1024;
bool fix_loaded(int base) override { // return (i+1) + (j+1)*1024;
const int max_state = nle::xy2s(nsize,nsize);
bool need_fix = false;
for (int ix=0;ix<nx && !need_fix;ix++)
......@@ -538,13 +533,13 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
return true;
}
virtual bool may_move_NL(int bi,int bj,int dir) const {
bool may_move_NL(int bi,int bj,int dir) const override {
for (int k=0;k<nsize;k++)
if (!nle::isL(ca::getfixd(bi+side[dir][k].x,bj+side[dir][k].y))) return false;
return true;
}
virtual void do_move_NL(int bi,int bj,int dir) {
void do_move_NL(int bi,int bj,int dir) override {
ca::dirs.move(bi,bj,dir);
int opp = oppdir[dir];
for (int k=0;k<nsize;k++)
......@@ -552,7 +547,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
nle::put_N(bi,bj);
}
virtual void print_neighbourhood(int bx,int by,int dir) {
void print_neighbourhood(int bx,int by,int dir) const override {
int x0 = -1, x1 = nsize+1;
int y0 = -1, y1 = nsize+1;
switch(dir) {
......@@ -573,7 +568,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
}
}
virtual void do_move_group_NL(int label,int dir) {
void do_move_group_NL(int label,int dir) override {
switch(dir) {
case 0: { // up
for (int ix=0;ix<nx;ix++) {
......@@ -625,7 +620,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
public:
virtual void fill_debug() {
void fill_debug() override {
ca::fill(nle::L);
const int bx = nx/2;
const int by = ny/2;
......@@ -743,7 +738,7 @@ class NLE_sqr4_CA : public NLE_sqr_CA<hood_vonNeumann> {
}
}
virtual void setData() {
void setData() override {
logfn("NLE_sqr4_CA","");
const int ns = nsize;
const int szn = 8*nsize-2;
......@@ -859,7 +854,7 @@ class NLE_sqr4_CA : public NLE_sqr_CA<hood_vonNeumann> {
*/
}
virtual std::array<int,3> neighborhood(const int x,const int y) const {
std::array<int,3> neighborhood(const int x,const int y) const override {
int count_n = 0;
int count_l = 0;
int count_e = 0;
......@@ -872,7 +867,7 @@ class NLE_sqr4_CA : public NLE_sqr_CA<hood_vonNeumann> {
return { count_n, count_l, count_e };
}
virtual int count_N_neighbors(int bx,int by) {
int count_N_neighbors(int bx,int by) const override {
if (nsize == 1) return neighborhood(bx,by)[0];
const int sLT = xy2s(0,0);
const int sLB = xy2s(0,nsize-1);
......@@ -886,7 +881,7 @@ class NLE_sqr4_CA : public NLE_sqr_CA<hood_vonNeumann> {
return c0[0] + c1[0] + c2[0] + c3[0];
}
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) {
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) const {
int count_n = 0;
int count_l = 0;
int count_e = 0;
......@@ -901,7 +896,7 @@ class NLE_sqr4_CA : public NLE_sqr_CA<hood_vonNeumann> {
return { count_n, count_l, count_e };
}
virtual std::array<int,3> test_count_nl(int bx,int by,int dir) {
std::array<int,3> test_count_nl(int bx,int by,int dir) const override {
const auto c1 = test_count_nle_on_line (bx+td[dir][1][0],by+td[dir][1][1],td[dir][1][2],td[dir][1][3],td[dir][1][4],td[dir][1][5],td[dir][1][6]);
const auto c2 = test_count_nle_on_line (bx+td[dir][2][0],by+td[dir][2][1],td[dir][2][2],td[dir][2][3],td[dir][2][4],td[dir][2][5],td[dir][2][6]);
const auto c0 = test_count_nle_on_line (bx+td[dir][0][0],by+td[dir][0][1],td[dir][0][2],td[dir][0][3],td[dir][0][4],td[dir][0][5],td[dir][0][6]);
......@@ -1035,7 +1030,7 @@ class NLE_sqr8_CA : public NLE_sqr_CA<hood_Moore> {
}
virtual void setData() {
void setData() override {
logfn("NLE_sqr8_CA","");
const int ns = nsize;
const int szn = 8*ns-2;
......@@ -1158,7 +1153,7 @@ class NLE_sqr8_CA : public NLE_sqr_CA<hood_Moore> {
// }
}
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) {
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) const {
int count_n = 0;
int count_l = 0;
int count_e = 0;
......@@ -1194,7 +1189,7 @@ class NLE_sqr8_CA : public NLE_sqr_CA<hood_Moore> {
return { count_n, count_l, count_e };
}
virtual std::array<int,3> test_count_nl(int bx,int by,int dir) {
std::array<int,3> test_count_nl(int bx,int by,int dir) const override {
const auto c0 = test_count_nle_on_line (bx+td[dir][0][0],by+td[dir][0][1],td[dir][0][2],td[dir][0][3],td[dir][0][4],td[dir][0][5],td[dir][0][6]);
const auto c1 = test_count_nle_on_line (bx+td[dir][1][0],by+td[dir][1][1],td[dir][1][2],td[dir][1][3],td[dir][1][4],td[dir][1][5],td[dir][1][6]);
const auto c2 = test_count_nle_on_line (bx+td[dir][2][0],by+td[dir][2][1],td[dir][2][2],td[dir][2][3],td[dir][2][4],td[dir][2][5],td[dir][2][6]);
......@@ -1228,7 +1223,7 @@ class NLE_sqr8_CA : public NLE_sqr_CA<hood_Moore> {
return { snn, snl, sll };
}
virtual int count_N_neighbors(int bx,int by) {
int count_N_neighbors(int bx,int by) const override {
if (nsize == 1) return neighborhood(bx,by)[0];
const int sLT = xy2s(0,0);
const int sLB = xy2s(0,nsize-1);
......@@ -1458,7 +1453,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
}
}
virtual void setData() {
void setData() override {
logfn("NLE_hex_CA","");
const int ns = nsize;
const int szn = (2*ns-1)*6;
......@@ -1567,7 +1562,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
}
}
bool fix_loaded(int base) { // x + y*nxsize + 1;
bool fix_loaded(int base) override { // x + y*nxsize + 1;
const int max_state = nle::xy2s(nxsize,nxsize);
bool need_fix = false;
for (int ix=0;ix<nx && !need_fix;ix++)
......@@ -1589,7 +1584,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
return true;
}
virtual bool may_move_NL(int bx,int by,int dir) const {
bool may_move_NL(int bx,int by,int dir) const override {
int d0 = (dir+ca::dirs.count-1)%ca::dirs.count;
for (int k=0;k<nsize-1;k++)
if (!isL(ca::getfixd(bx+side[d0][k].x,by+side[d0][k].y))) return false;
......@@ -1599,7 +1594,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
return true;
}
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) {
std::array<int,3> test_count_nle_on_line_l(int x,int y,int dx,int dy,int n,int initial_state,int final_state) const {
int count_n = 0;
int count_l = 0;
int count_e = 0;
......@@ -1628,7 +1623,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
return { count_n, count_l, count_e };
}
virtual std::array<int,3> test_count_nl(int bx,int by,int dir) {
std::array<int,3> test_count_nl(int bx,int by,int dir) const override {
const auto c0 = test_count_nle_on_line (bx+td[dir][0][0],by+td[dir][0][1],td[dir][0][2],td[dir][0][3],td[dir][0][4],td[dir][0][5],td[dir][0][6]);
const auto c1 = test_count_nle_on_line (bx+td[dir][1][0],by+td[dir][1][1],td[dir][1][2],td[dir][1][3],td[dir][1][4],td[dir][1][5],td[dir][1][6]);
const auto c2 = test_count_nle_on_line (bx+td[dir][2][0],by+td[dir][2][1],td[dir][2][2],td[dir][2][3],td[dir][2][4],td[dir][2][5],td[dir][2][6]);
......@@ -1673,7 +1668,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
return { snn, snl, sll };
}
virtual int count_N_neighbors(int bx,int by) {
int count_N_neighbors(int bx,int by) const override {
if (nsize == 1) return neighborhood(bx,by)[0];
const int ns = nsize;
const int sTL = xy2s(ns-1,0);
......@@ -1699,7 +1694,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
return snn;
}
virtual void do_move_NL(int bx,int by,int dir) {
void do_move_NL(int bx,int by,int dir) override {
XY nb(bx,by);
ca::dirs.move(nb,dir);
int opp = oppdir[dir];
......@@ -1712,7 +1707,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
put_N(nb);
}
virtual void do_move_group_NL(int label,int dir) {
void do_move_group_NL(int label,int dir) override {
const int nx = ca::nx;
const int ny = ca::ny;
switch(dir) {
......@@ -1834,7 +1829,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
}
}
void print_neighbourhood(int bx,int by,int dir) {
void print_neighbourhood(int bx,int by,int dir) const override {
int x0 = -1, x1 = 2*nsize;
int y0 = -1, y1 = 2*nsize;
switch(dir) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment