$$\rightleftharpoonup{xx}$$
$$\longleftharp{xx}$$,
$$\longrightharp{xx}$$,
1. Prepare Watershed Model and Provide Input Data for Optimization
- Create an i_SWAT database.
- Using a program called "rotator", build the database from multiple input databases including soils, weather, management and fertilizer.
- Alternatively, an existing SWAT run (possibly created with ArcSWAT or AVSWAT) can be imported with i_SWAT.exe. In this case, the program "swat_rewrite" can be used to replace management or other HRU information based on field-level data.
- Calibration and validation of the SWAT model should be performed at this point. The SWAT (version 2005) model incorporated within this Raccoon River Watershed EA modeling framework was originally calibrated and validated for a Total Maximum Daily Load (TMDL) study as described by Jha et al. (2010). Further calibration and validation of the SWAT model was conducted in support of the development of a Raccoon River Watershed Master Plan, as described in Agren, Inc. (2011), which is the SWAT model that was used for this study.
- Use a modified version of SWAT2005.exe, called SWAT2005GA.exe.
- Prepare file "watershed presets.csv" - This is a text file storing many of the settings specific to the Raccoon watershed. It is read by GeneticiSWAT and MapSWAT below to set multiple controls and data fields for the watershed with one click.
- Prepare the costs of conservation practice elements. For this example, these are stored in table [Practice Costs - Raccoon by County] in a database "Practice costs by subbasin Josh.mdb".
The total cost of a candidate solution is the sum of costs of conservation practices applied to watershed units ("hydrologic response units", or HRUs). The optimization program considers an optimal assignment of a single conservation practice from a particular set of conservation practices in every cropland HRU in the watershed. The sets of possible conservation practices assigned to an HRU are called allele sets.
- Create SWAT folders. For this run, 16 CPUs were used, meaning 16 copies of SWAT2005GA.exe were run in 16 separate folders (the same applies for systems with fewer CPUs, e.g. 4 folders should be created for a "quad-core" processor).
2. Select Optimization Parameters
- Optimization is controlled by the program called "GeneticISWAT". To perform optimization, open GeneticISWAT.exe.
- Go to "File", then "Open" and select the i_SWAT database "Raccoon GA.mdb".
- Go to "File", then "Configuration" to assign the paths to SWAT model executables (SWAT2005GA.exe).
- Go to "Execute", then "Select Allele Set". This step determines the combinations of conservation practices used in optimization. For this run, allele set #14 was used, which has 23 combinations of conservation practices. Available allele sets are stored in the configuration file "Alleles.csv".
- Go to "Execute", then select "SPEA2 Archive Baseline Aware Subset" to perform multiobjective optimization using the SPEA2 evolutionary algorithm.

Figure 1. Setting optimization objectives and parameters.
Optimization parameters to be selected:
Preset: Select the watershed to be optimized. Clicking "Apply" selects entries from the presets file "watershed presets.csv" to fill control values on this screen.
Output Variable: Select the environmental objectives for optimization. As selected (N Outlet, P Outlet), this defines a 3-dimensional objective function: Nitrogen (Organic N + NO3 + NH4 + NO2) averaged for 5 years at the outlet, Phosphorus (Organic P + Mineral P) averaged for 5 years at the outlet, and the total cost of conservation practices. Note that this will create a 3-dimensional tradeoff frontier. Alternative output variables can be selected, where the multiobjective program is to minimize ({Output Variable}, Total Cost).
Population size: Set initial population size. This determines the initial number of candidate solutions. When "Seed with each allele" option is selected, candidate solutions representing a uniform application of each conservation practice specified in the allele set to all cropland HRUs in the watershed are created first. The remaining candidate solutions are created by a random assignment of conservation practices from the allele set to cropland HRUs. When selecting the "Seed with each allele" option, one needs to make sure that the initial population size is at least as large as the number of alleles in an allele set (23 in this demonstration).
Number of generations: Set the desired number of generations (iterations) for the optimization run (note that the run can be restarted).
Crossover probability: When two candidate solutions are selected for creating new candidate solutions, crossover probability specifies the probability that distinct new solutions are created (set to 1 for this demonstration).
Size of temporary population: This determines the number of new candidate solutions created. Processor resources are used most efficiently when this value is an integer multiple of the number of processor threads (16 in this demonstration).
Mutation probability: Specify the probability of random change in HRU assignment to another conservation practice from the allele set. (It is set to 0.03 for this demonstration).
Number of threads: Select the number of processors or threads used. 16 is used in this demonstration.
Curve No. calibration factor: This is provided from the SWAT model calibration.
Save Population in text file: This is important to select if one wishes to restart the optimization run after the specified number of iterations is completed. Checking this option produces a text file with the allele values of every HRU in every surviving candidate solution (individual). This can be read back in to restart and continue a run.
Secondary optimization parameters
First Year: Must be set to a year after start of historical weather information, and no later than 7 years before end of this data.
Price of Corn: Used with the yield loss equation to estimate the cost of fertilizer reductions.
Scoring Method: SPEA2 Archive. Scoring determines how likely a surviving individual is to be selected for crossover.
Purge Method: Dominated. Individuals which are worse in all 3 dimensions are dominated and purged.
HUC Source: Set to "Specified Location", meaning the value "7100006" from the following field "Watershed HUC" is used to find a row in the HUC Zone table. The value "07100006" is the eight-digit HUC code for the Raccoon watershed.
Cost Source: Set to "County (HRU Location Code)" to indicate that costs other than CRP will be determined by county FIPS codes in the practice costs table above.
Cost Source CRP: Set to "1 Location" to indicate that CRP cost will be determined by county FIPS codes in the practice costs table above.
SWAT version: SWAT2005
3. Representative Results
GeneticiSWAT.exe produces a log file showing the settings and results for all candidate solutions (individuals), as well as a "save" file which encodes the results from the final algorithm iteration and which can be used to restart the optimization run.
At this point, one can visualize the entire set of Pareto-efficient solutions (the tradeoff frontier) by following the steps below:
- Run GeneticiSWAT;
- Go to "File", then "Open" to open the i_SWAT database "Raccoon GA.mdb".
- Go to "Execute", then "Export HRU List". Save file as "Raccoon Allele HRU.txt".
- Produce an animation by running Mapswat.exe, selecting "Execute" and then "3d Animation".

Figure 2. Screenshot for creating "snapshots" for 3-dimensional frontier visualization.
Output is a series of files which can be rendered all at once into image files by using POV-RAY program and selecting "Render", then "File Queue". The images can be used on their own or combined into a movie showing the algorithm progression.

Figure 3. Static visualization of the tradeoff frontier.
If desired, a movie showing the algorithm progression can be created by running "Framescanner.exe" and following these steps:
- Go to "File", then "New", then "File", then "Import", then "PNG Files". Select the static images.
- To create a movie, go to "File", then "Export", then "AVI".
- Select codec "DIB" to create AVI files from batches of image files.
Each point in the frontier represents a watershed configuration (a specific assignment of conservation practices on a landscape). Maps of these configurations can be seen for the entire frontier by following these steps:
- Run Mapswat.exe, select "Execute", then "Map Animation".
- Select "Raccoon" from preset list and click "Apply".
- Select "Layout 7 (Raccoon)" from Map Layout list, then click "OK".

Figure 4. Screenshot of creating a map of each individual in the final frontier.
Exporting specific watershed configurations (individuals) of interest.
Often a question of interest is to select specific watershed configurations (individuals) achieving particular water quality objectives. For example, one may wish to find an individual in the frontier which reduces Nitrogen by 30% and Phosphorus by 20% relative to baseline loadings. MapSWAT allows one to search the frontier for the individual with the smallest Euclidean distance to the specified objective. This can be done by doing the following:
- Open MapSWAT.exe. Select "Execute" | "Search".

Figure 5. Screenshot of searching for a specific individual in the frontier based on water quality objectives.
- Enter minimum and maximum reduction targets Tmin and Tmax as well as an interval Tint. Also enter a specific percent reduction in Nitrogen (Nspec) from baseline in the "% reduction" space next to N Baseline, and percent reduction in Phosphorus (Pspec) in the "% reduction" next to Phosphorus baseline. The program produces output in a popup screen:

Figure 6. Screenshot of search output
- Click "Copy Text" and paste into a spreadsheet. Three tables are produced. In the first are individuals nearest to N and P targets of the same percent reduction, which ranges from Tmin to Tmax by Tint. Just below this the closest single individual to the target (Nspec, Pspec) appears. Second, a table giving nearest individuals where the P target ranges from Tmin to Tmax while N is held constant near Nspec. Third, a table giving individuals nearest N targets ranging from Tmin to Tmax while P is held constant near Pspec. In this case, the closest individual to a 30% N reduction was ID 8423 with an N value of 14,637,279.60. Here is the map showing the spatial distribution of conservation practices and the location of this watershed configuration in the tradeoff frontier:

Figure 7. Screenshot of a sample map describing the selected individual in the frontier. Click here to view larger figure.
Exporting map data for further analysis is possible by following these steps:
- Run Mapswat.exe, select "Execute", then "Export Map Data".
- Select "Raccoon" from preset list and click "Apply".
- Enter the ID of a watershed configuration (individual) (8423 shown), check "Show Allele Properties" and "Show Costs", and then click "OK". This data can be used to create custom maps of the selected watershed configuration using a GIS program.
| Name of Program | Source | Description |
| Rotator | CARD | Creates and fills an i_SWAT database with soil, weather, and management data for a watershed. |
| Swat2005GA.exe | USDA Grassland, Soil & Water Research Laboratory | Watershed simulation model |
| i_SWAT.exe | CARD | SWAT database interface |
| GeneticISWAT.exe | CARD | Evolutionary algorithm SWAT controller. Incorporates GALib from http://lancet.mit.edu/ga/. |
| MapSWAT.exe | CARD | Reads i_SWAT databases and shapefiles, produces images of generations and individuals. |
| POV-Ray | Povray.org | Persistence of Vision raytracer. |
| Framescanner.exe | Todd Campbell | PNG image to AVI converter |
| Windows Live Movie Maker | Microsoft | Used to compress AVI to WMV |
Table 1. Table of programs required.
| Name of File | Type | Description |
| Raccoon GA.mdb | Access database | Structure and management descriptions of Raccoon watershed. Read by GeneticiSWAT and MapSWAT. |
| watershed presets.csv | Text | Setting presets for GeneticiSWAT.exe and MapSWAT |
| Alleles.csv | Text | List of allele sets for evolutionary algorithm. |
| Raccoon Allele HRU.txt | Text | File created by GeneticISWAT listing those alleles determined to be cropland. Read by MapSWAT. |
| Practice costs by subbasin Josh.mdb | Access Database | Costs by management practice and county. |
| Terrace Zones.mdb | Access Database | Table [HUC Data] holds the terrace and yield zone numbers for the watershed. |
| NRI Budgets.mdb | Access Database | Read by GeneticISWAT.exe for crop & machine tables which are not used in this run. |
| phucrp 2008-12-15.dat | Text | Plant Heat Unit lookup table, not used in this run. |
| Management.mdb | Access Database | Rotation lookup table, not used in this run. |
| Raccoon GA 2011-09-28 1313.log, Raccoon GA 2011-09-29 0732.log, Raccoon GA 2011-10-07 0644.log | Text | Log files of GeneticISWAT run. |
| Raccoon GA.wmv | Animation | 3d display of individuals by generation |
| Subbasin.shp | ESRI Shapefile | Outlines of subbasins in the watershed. |
| Raccoon Map.wmv | Animation | Display of dominant alleles for each subbasin for each individual on the frontier. |
Table 2. Table of sample files required.