Remove unneeded properties
This commit is contained in:
parent
952e31449f
commit
d69402e32e
@ -10,7 +10,7 @@
|
|||||||
void DLASystem::Update() {
|
void DLASystem::Update() {
|
||||||
if (lastParticleIsActive == 1) {
|
if (lastParticleIsActive == 1) {
|
||||||
moveLastParticle();
|
moveLastParticle();
|
||||||
} else if (numParticles < endNum) {
|
} else if (this->particleList.size() < (size_t) endNum) {
|
||||||
addParticleOnAddCircle();
|
addParticleOnAddCircle();
|
||||||
setParticleActive();
|
setParticleActive();
|
||||||
} else {
|
} else {
|
||||||
@ -20,17 +20,16 @@ void DLASystem::Update() {
|
|||||||
|
|
||||||
void DLASystem::clearParticles() {
|
void DLASystem::clearParticles() {
|
||||||
// delete particles and the particle list
|
// delete particles and the particle list
|
||||||
for (int i = 0; i < numParticles; i++) {
|
for (size_t i = 0; i < this->particleList.size(); i++) {
|
||||||
delete particleList[i];
|
delete particleList[i];
|
||||||
}
|
}
|
||||||
particleList.clear();
|
particleList.clear();
|
||||||
numParticles = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove any existing particles and setup initial condition
|
// remove any existing particles and setup initial condition
|
||||||
void DLASystem::Reset() {
|
void DLASystem::Reset() {
|
||||||
// stop running
|
// stop running
|
||||||
running = 0;
|
running = false;
|
||||||
|
|
||||||
clearParticles();
|
clearParticles();
|
||||||
|
|
||||||
@ -50,11 +49,6 @@ void DLASystem::Reset() {
|
|||||||
// add a single particle at the origin
|
// add a single particle at the origin
|
||||||
double pos[] = {0.0, 0.0};
|
double pos[] = {0.0, 0.0};
|
||||||
addParticle(pos);
|
addParticle(pos);
|
||||||
|
|
||||||
// set the view
|
|
||||||
int InitialViewSize = 40;
|
|
||||||
setViewSize(InitialViewSize);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the value of a grid cell for a particular position
|
// set the value of a grid cell for a particular position
|
||||||
@ -87,7 +81,6 @@ void DLASystem::addParticle(double pos[]) {
|
|||||||
Particle *p = new Particle(pos);
|
Particle *p = new Particle(pos);
|
||||||
// push_back means "add this to the end of the list"
|
// push_back means "add this to the end of the list"
|
||||||
particleList.push_back(p);
|
particleList.push_back(p);
|
||||||
numParticles++;
|
|
||||||
|
|
||||||
// pos coordinates should be -gridSize/2 < x < gridSize/2
|
// pos coordinates should be -gridSize/2 < x < gridSize/2
|
||||||
setGrid(pos, 1);
|
setGrid(pos, 1);
|
||||||
@ -131,23 +124,9 @@ void DLASystem::setPosNeighbour(double setpos[], double pos[], int val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the view is smaller than the kill circle then increase the view area (zoom out)
|
|
||||||
void DLASystem::updateViewSize() {
|
|
||||||
double mult = 1.2;
|
|
||||||
if (viewSize < 2.0 * killCircle) {
|
|
||||||
setViewSize(viewSize * mult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the view to be the size of the add circle (ie zoom in on the cluster)
|
|
||||||
void DLASystem::viewAddCircle() {
|
|
||||||
setViewSize(2.0 * addCircle); // factor of 2 is to go from radius to diameter
|
|
||||||
}
|
|
||||||
|
|
||||||
// when we add a particle to the cluster, we should update the cluster radius
|
// when we add a particle to the cluster, we should update the cluster radius
|
||||||
// and the sizes of the addCircle and the killCircle
|
// and the sizes of the addCircle and the killCircle
|
||||||
void DLASystem::updateClusterRadius(double pos[]) {
|
void DLASystem::updateClusterRadius(double pos[]) {
|
||||||
|
|
||||||
double rr = distanceFromOrigin(pos);
|
double rr = distanceFromOrigin(pos);
|
||||||
if (rr > clusterRadius) {
|
if (rr > clusterRadius) {
|
||||||
clusterRadius = rr;
|
clusterRadius = rr;
|
||||||
@ -160,7 +139,6 @@ void DLASystem::updateClusterRadius(double pos[]) {
|
|||||||
if (addCircle < check) {
|
if (addCircle < check) {
|
||||||
addCircle = check;
|
addCircle = check;
|
||||||
killCircle = killRatio * addCircle;
|
killCircle = killRatio * addCircle;
|
||||||
updateViewSize();
|
|
||||||
}
|
}
|
||||||
checkStop();
|
checkStop();
|
||||||
}
|
}
|
||||||
@ -171,7 +149,7 @@ void DLASystem::moveLastParticle() {
|
|||||||
int rr = rgen.randomInt(4); // pick a random number in the range 0-3, which direction do we hop?
|
int rr = rgen.randomInt(4); // pick a random number in the range 0-3, which direction do we hop?
|
||||||
double newpos[2];
|
double newpos[2];
|
||||||
|
|
||||||
Particle *lastP = particleList[numParticles - 1];
|
Particle *lastP = particleList[this->particleList.size() - 1];
|
||||||
|
|
||||||
setPosNeighbour(newpos, lastP->pos, rr);
|
setPosNeighbour(newpos, lastP->pos, rr);
|
||||||
|
|
||||||
@ -179,25 +157,25 @@ void DLASystem::moveLastParticle() {
|
|||||||
//cout << "#deleting particle" << endl;
|
//cout << "#deleting particle" << endl;
|
||||||
setGrid(lastP->pos, 0);
|
setGrid(lastP->pos, 0);
|
||||||
particleList.pop_back(); // remove particle from particleList
|
particleList.pop_back(); // remove particle from particleList
|
||||||
numParticles--;
|
|
||||||
setParticleInactive();
|
setParticleInactive();
|
||||||
}
|
}
|
||||||
// check if destination is empty
|
// check if destination is empty
|
||||||
else if (readGrid(newpos) == 0) {
|
else if (readGrid(newpos) == 0) {
|
||||||
setGrid(lastP->pos, 0); // set the old grid site to empty
|
setGrid(lastP->pos, 0); // set the old grid site to empty
|
||||||
// update the position
|
// update the position
|
||||||
particleList[numParticles - 1]->pos[0] = newpos[0];
|
particleList[this->particleList.size() - 1]->pos[0] = newpos[0];
|
||||||
particleList[numParticles - 1]->pos[1] = newpos[1];
|
particleList[this->particleList.size() - 1]->pos[1] = newpos[1];
|
||||||
setGrid(lastP->pos, 1); // set the new grid site to be occupied
|
setGrid(lastP->pos, 1); // set the new grid site to be occupied
|
||||||
|
|
||||||
// check if we stick
|
// check if we stick
|
||||||
if (checkStick()) {
|
if (checkStick()) {
|
||||||
|
cout << lastP->pos[0] << "," << lastP->pos[1] << endl;
|
||||||
//cout << "stick" << endl;
|
//cout << "stick" << endl;
|
||||||
setParticleInactive(); // make the particle inactive (stuck)
|
setParticleInactive(); // make the particle inactive (stuck)
|
||||||
updateClusterRadius(lastP->pos); // update the cluster radius, addCircle, etc.
|
updateClusterRadius(lastP->pos); // update the cluster radius, addCircle, etc.
|
||||||
|
|
||||||
if (numParticles % 100 == 0 && logfile.is_open()) {
|
if (this->particleList.size() % 100 == 0 && logfile.is_open()) {
|
||||||
logfile << numParticles << " " << clusterRadius << endl;
|
logfile << this->particleList.size() << " " << clusterRadius << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -212,7 +190,7 @@ void DLASystem::moveLastParticle() {
|
|||||||
|
|
||||||
// check if the last particle should stick (to a neighbour)
|
// check if the last particle should stick (to a neighbour)
|
||||||
int DLASystem::checkStick() {
|
int DLASystem::checkStick() {
|
||||||
Particle *lastP = particleList[numParticles - 1];
|
Particle *lastP = particleList[this->particleList.size() - 1];
|
||||||
int result = 0;
|
int result = 0;
|
||||||
// loop over neighbours
|
// loop over neighbours
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
@ -229,7 +207,6 @@ int DLASystem::checkStick() {
|
|||||||
// constructor
|
// constructor
|
||||||
DLASystem::DLASystem() {
|
DLASystem::DLASystem() {
|
||||||
cout << "creating system, gridSize " << gridSize << endl;
|
cout << "creating system, gridSize " << gridSize << endl;
|
||||||
numParticles = 0;
|
|
||||||
endNum = 1000;
|
endNum = 1000;
|
||||||
|
|
||||||
// allocate memory for the grid, remember to free the memory in destructor
|
// allocate memory for the grid, remember to free the memory in destructor
|
||||||
@ -237,7 +214,6 @@ DLASystem::DLASystem() {
|
|||||||
for (int i = 0; i < gridSize; i++) {
|
for (int i = 0; i < gridSize; i++) {
|
||||||
grid[i] = new int[gridSize];
|
grid[i] = new int[gridSize];
|
||||||
}
|
}
|
||||||
slowNotFast = 1;
|
|
||||||
// reset initial parameters
|
// reset initial parameters
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
|
|||||||
37
DLASystem.h
37
DLASystem.h
@ -23,7 +23,6 @@ private:
|
|||||||
// these are private variables and functions that the user will not see
|
// these are private variables and functions that the user will not see
|
||||||
// list of particles
|
// list of particles
|
||||||
vector<Particle *> particleList;
|
vector<Particle *> particleList;
|
||||||
int numParticles;
|
|
||||||
|
|
||||||
// delete particles and clear the particle list
|
// delete particles and clear the particle list
|
||||||
void clearParticles();
|
void clearParticles();
|
||||||
@ -38,10 +37,6 @@ private:
|
|||||||
static const int gridSize = 1600;
|
static const int gridSize = 1600;
|
||||||
int **grid; // this will be a 2d array that stores whether each site is occupied
|
int **grid; // this will be a 2d array that stores whether each site is occupied
|
||||||
|
|
||||||
// the window draws only part of the grid, viewSize controls how much...
|
|
||||||
double viewSize;
|
|
||||||
double drawScale;
|
|
||||||
|
|
||||||
// random number generator, class name is rnd, instance is rgen
|
// random number generator, class name is rnd, instance is rgen
|
||||||
rnd rgen;
|
rnd rgen;
|
||||||
|
|
||||||
@ -56,7 +51,6 @@ private:
|
|||||||
double addRatio; // how much bigger the addCircle should be, compared to cluster radius
|
double addRatio; // how much bigger the addCircle should be, compared to cluster radius
|
||||||
double killRatio; // how much bigger is the killCircle, compared to the addCircle
|
double killRatio; // how much bigger is the killCircle, compared to the addCircle
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// these are public variables and functions
|
// these are public variables and functions
|
||||||
|
|
||||||
@ -65,10 +59,7 @@ public:
|
|||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
// is the simulation running (1) or paused (0) ?
|
// is the simulation running (1) or paused (0) ?
|
||||||
int running;
|
bool running;
|
||||||
|
|
||||||
// slowNotFast is +1 for slow running, 0 for fast
|
|
||||||
int slowNotFast;
|
|
||||||
|
|
||||||
// lastParticleIsActive is +1 if there is an active particle in the system, otherwise 0
|
// lastParticleIsActive is +1 if there is an active particle in the system, otherwise 0
|
||||||
int lastParticleIsActive;
|
int lastParticleIsActive;
|
||||||
@ -88,31 +79,9 @@ public:
|
|||||||
// check whether we should stop (eg the cluster has reached the edge of the grid)
|
// check whether we should stop (eg the cluster has reached the edge of the grid)
|
||||||
int checkStop();
|
int checkStop();
|
||||||
|
|
||||||
// stop/start the algorithm
|
void setRunning() { running = true; }
|
||||||
void setRunning() { if (checkStop() == true) running = 1; }
|
|
||||||
|
|
||||||
void pauseRunning() { running = 0; }
|
void pauseRunning() { running = false; }
|
||||||
|
|
||||||
// set whether it runs fast or slow
|
|
||||||
void setSlow() { slowNotFast = 1; }
|
|
||||||
|
|
||||||
void setFast() { slowNotFast = 0; }
|
|
||||||
|
|
||||||
void setSuperFast() { slowNotFast = -1; }
|
|
||||||
|
|
||||||
// set which part of the grid is visible on the screen
|
|
||||||
// basically the screen shows co-ordinates -vv < x < vv
|
|
||||||
// where vv is the input value
|
|
||||||
void setViewSize(double vv) {
|
|
||||||
viewSize = vv;
|
|
||||||
drawScale = 2.0 / viewSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the killcircle is almost as big as the view then increase the view
|
|
||||||
void updateViewSize();
|
|
||||||
|
|
||||||
// set the view to be the approx size of the addCircle
|
|
||||||
void viewAddCircle();
|
|
||||||
|
|
||||||
// if pos is outside the cluster radius then set clusterRadius to be the distance to pos.
|
// if pos is outside the cluster radius then set clusterRadius to be the distance to pos.
|
||||||
void updateClusterRadius(double pos[]);
|
void updateClusterRadius(double pos[]);
|
||||||
|
|||||||
@ -17,7 +17,7 @@ int main(int argc, char **argv) {
|
|||||||
int seed = 6;
|
int seed = 6;
|
||||||
cout << "setting seed " << seed << endl;
|
cout << "setting seed " << seed << endl;
|
||||||
sys->setSeed(seed);
|
sys->setSeed(seed);
|
||||||
sys->running = true;
|
sys->setRunning();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: We run at max speed as rendering is handled by a different engine so we simply want to hjand
|
* NOTE: We run at max speed as rendering is handled by a different engine so we simply want to hjand
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user