/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* main.c
* Copyright (C) DMGualtieri 2011
*
* Levy_Flight is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Levy_Flight is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
//Random walk and a particular type of Levy Flight are implemented
#include
#include
#include
#include
long int steps;
long int i;
long int j;
int k, walk, distance_flag;
float x,y,x_old,y_old;
float delta_x, delta_y, distance;
int wander = 10;
float centers[100][2] = {{0,0}};
FILE *outdata;
//generates a psuedo-random float between -0.5 and 0.5
float randfloat()
{
return (((float)rand()/RAND_MAX)-0.5);
}
int main(int argc, char *argv[])
{
if (argc<3)
{
printf("Usage: random_walk type number_of_steps\n");
//type = 0 is normal; type = 1 is Levy Flight
exit(1);
}
//Seed random number generator
srand ( (unsigned)time ( NULL ) );
//Open output datafile
if ((outdata = fopen("walk_data.txt","w"))==NULL)
{printf ("\nOutput file cannot be opened.\n");
exit (1);}
else
{
printf("Output file = walk_data.txt");
}
//Set origin
x=0;
y=0;
fprintf(outdata,"%f\t%f\n",x,y);
walk = atoi(argv[1]);
//walk = 0 is normal; walk = 1 is Levy Flight
steps = (long int)atoi(argv[2]);
if(walk == 0)
{
printf("\nnormal random walk");
printf("\nsteps = %ld\n",steps);
for(j = 1;j0)
{
while(distance_flag != 0)
{
// We wander here, arbitrarily up to a maximum of 2*sqrt(steps/wander),
// and we check to maintain a spacing from other walk centers
x = x_old + 2*sqrt(steps/wander)*randfloat();
y = y_old + 2*sqrt(steps/wander)*randfloat();
printf("x = %f\ty = %f\n",centers[i][0],centers[i][1]);
// Check spacing of centers
distance_flag = 0;
k=1;
while(k