//--------------------------------------------------------------------------- /*------------------------------------------------------------------------------ SMS3 main file for the CodeGear console (batch) version The program reads an input file control.txt which specifies the ID, landscape details, starting location and goal location for movements to be simulated. For each ID, sets of parameter combinations required to run SMS3 are read from the parameters.txt file: perceptual range (PR) evaluation method, PR (upon changing PR, the landscape's 'memory' of previously calculated effective costs is reset), directional persistence (DP), goal bias (GB) , memory size. Thus, if there are C valid records in control.txt and P valid records in parameters.txt, there will be C x P records written to the output log.csv file. The total number of paths simulated will depend on the values of the Npaths field in each control.txt record. Optionally, after each combination of parameters is completed, a landscape density file (ArcGIS raster export format) can be written as a record of the frequency with which each landscape square is visited by the individuals released (controlled by WRITE_LANDS in Parameters.h). The landscape number is allocated incrementally, and changes when either the cost grid or the target grid changes in the control.txt file. Author: Steve Palmer, University of Aberdeen Last updated: 1 May 2012 ------------------------------------------------------------------------------*/ #include #include #include "Landscape.h" #include "Animal.h" #include "MoveInd.h" #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused StochasticLib1 sto1a(SEED); // set up global landscape pointer Landscape* pLandscape; int main(int argc, char* argv[]) { int i,j,t0,t1,parameterset,Npaths,goaltype,cellsize,move; locn start,source,goal,origin,XYmax; int landID,maxcost,prevnodatacost; int nodatacost; // cost to use in place of 'nodata' value int maxsteps; // max. no. of steps used (unless NOLIMIT is applied) pLandscape = 0; parameterset = 0; char txt[20]; char id[20],cost[20],target[20]; char prevcost[20],prevtarget[20]; int startpatch,Xstart,Ystart,Xgoal,Ygoal; char costgrid[20],tgtgrid[20]; bool new_landscape; bool files_ok = 1; bool start_ok = 0; t0 = time(0); // open input control file ifstream inctrl ("control.txt"); if (!inctrl.is_open()) { cout<>txt; } // open log file ofstream outlog ("log.csv"); if (!outlog.is_open()) { cout<>id; new_landscape = 1; while (files_ok && id[0]) { inctrl>>cost>>target>>nodatacost>>maxsteps>>Npaths >>Xstart>>Ystart>>startpatch>>goaltype>>Xgoal>>Ygoal; cout< 2) { cout<get_id(); maxcost = pLandscape->ReadLandscape(costgrid,tgtgrid,"null"); new_landscape = 0; parameterset = 0; } if (maxcost < 1) { cout<get_cellsize(); if (maxcost > 0) { origin = pLandscape->get_origin(); XYmax = pLandscape->get_XYmax(); if (start.x < origin.x || start.y < origin.y || start.x > XYmax.x || start.y > XYmax.y) { cout< 0 && start_ok && nodatacost > 0 && maxsteps > 0) { // run SMS for the current landscape int method,pr,ms,prevpr,prevmethod; double dp,gb; // open parameter control file ifstream inparms ("parameters.txt"); if (!inparms.is_open()) { cout<>txt; // cout<<"i = "<ResetEffCosts(); } // reset all visits counters to zero pLandscape->ResetVisits(0); for (i = 0; i < Npaths; i++) { // release N individuals Animal* pAnimal = new Animal(source.x,source.y,0,0.5); pAnimal->set_movement(pr,method,dp,gb,ms,nodatacost); pAnimal->set_goal(goaltype,goal.x,goal.y); // reset visits counters in the current landscape pLandscape->ResetVisits(1); move = move_ind(pAnimal,pLandscape,source,startpatch,parameterset,id,maxsteps); delete pAnimal; if (move == 999) { cout<get_cellsize() <<","<WriteLandFile(4,parameterset); #endif // retain current pr and method prevpr = pr; prevmethod = method; // read next data record method = 0; // to ensure valid method is read if (files_ok) inparms>>method; parameterset++; // cout<<"method = "< 0"< 0"<>id; } cout<>i; return 0; } //---------------------------------------------------------------------------