Difference between revisions of "Tmp"

From assela Pathirana
Jump to navigationJump to search
Line 1: Line 1:
=Putting it all together -- Optimization and EPAnet=
=Putting it all together -- Optimization and EPAnet=
In this lesson, we push the abilities we have gained to the limit! We link two code libraries, namely, Evolving objects -- a versatile genetic algorithm code and EPAnet (toolkit) a pipe network calculation model by writing some relatively simple code and create a running program. The following section explains the problem we have selected to solve (please note that the problem itself is of secondary importance here, what we are trying to do is to hone the skills we have gained and build confidence to attack bigger coding projects).
In this lesson, we push the abilities we have gained to the limit! We link two code libraries, namely, Evolving objects -- a versatile genetic algorithm code and EPAnet (toolkit) a pipe network calculation model by writing some relatively simple code and create a running program. The following section explains the problem we have selected to solve (please note that the problem itself is of secondary importance here, what we are trying to do is to hone the skills we have gained and build confidence to attack bigger coding projects).
==Problem==
[[Image:cbcpp_pipe_network1.png|The pipe network.|Thumb]]
The figure on the left shows a water supply network with a reservoir, seven pipe segments conveying water and five junctions that have different demands. We want to compute the most economical pipe diameters for each segment while maintaining a minimum pressure head of 10 m at all junctions. You can open the [[image:cbcpp_pipe_network1.inp|input file]] in Epanet 2 software to view the network.
Our plan is to use a Genetic Algorithm to optimize the pipe diameters. For this we need to connect Epanet Software to a genetic algorithm code.
==Plan==
We will use the Epanet Toolkit, a programming interface designed to run Epanet 2.0 programmatically without the standard graphical interface. For the Genetic Algorithm part, we'll use Evolving objects a free and open source  package for evolutionary computations.
Evolving objects can be downloaded from [http://eodev.sourceforge.net/ eodev]] website. Epanet toolkit can be downloaded from [[http://www.epa.gov/nrmrl/wswrd/epanet.html US-EPA]]. However, for this exercise you may use the already downloaded versions of these tools. Download the file [[Image:cbcpp_EO.zip|cbcpp_EO.zip]] into your computer and extract it to a new folder (say <tt>E:\GA\EO</tt>). This will create four subfolders,
<pre>
code
data
eo-1.0
epanet_tools
</pre>
We use code folder to keep all the code we write (not the code libraries we use!). It already have the files:
<pre>
ESEA.cpp
real_value.h
</pre>
<tt>ESEA.cpp</tt> is a c++ program that can be used to access the EO Genetic algorithm functions. <tt>real_value.h</tt> has the <tt>cost function</tt> for the GA. We'll learn more about this later.
<tt>data</tt> folder where we shall keep all our data, has the water distribution network file.
<tt>eo-1.0</tt> and <tt>epanet_tools</tt> have the evolving objects and epanet toolkit code libraries.
==Solution==
We shall attack our problem in a piecemeal fashion, in the steps given below:
# Get EO to solve a small GA problem.
# Replace the cost function with our own.
# Use epanet_toolkit to run Epanet on our water supply network and use the results to evaluate a cost function.
Usually this step-by-step approach is less error-prone than attempting the whole task once.
==Running a GA==
Create a new folder called <tt>projects</tt> under the same folder that has sub-folders of <tt>code</tt>, <tt>data</tt>, etc. This is where we shall keep the visual studio express edition related (platform specific) stuff. Open visual C++ and reate a new empty project EPGA in that folder. Add the following files in the code folder to the project.
<pre>
ESEA.cpp
real_value.h
</pre>

Revision as of 09:59, 8 April 2007

Putting it all together -- Optimization and EPAnet

In this lesson, we push the abilities we have gained to the limit! We link two code libraries, namely, Evolving objects -- a versatile genetic algorithm code and EPAnet (toolkit) a pipe network calculation model by writing some relatively simple code and create a running program. The following section explains the problem we have selected to solve (please note that the problem itself is of secondary importance here, what we are trying to do is to hone the skills we have gained and build confidence to attack bigger coding projects).

Problem

Thumb The figure on the left shows a water supply network with a reservoir, seven pipe segments conveying water and five junctions that have different demands. We want to compute the most economical pipe diameters for each segment while maintaining a minimum pressure head of 10 m at all junctions. You can open the File:Cbcpp pipe network1.inp in Epanet 2 software to view the network.

Our plan is to use a Genetic Algorithm to optimize the pipe diameters. For this we need to connect Epanet Software to a genetic algorithm code.

Plan

We will use the Epanet Toolkit, a programming interface designed to run Epanet 2.0 programmatically without the standard graphical interface. For the Genetic Algorithm part, we'll use Evolving objects a free and open source package for evolutionary computations.

Evolving objects can be downloaded from eodev] website. Epanet toolkit can be downloaded from [US-EPA]. However, for this exercise you may use the already downloaded versions of these tools. Download the file cbcpp_EO.zip into your computer and extract it to a new folder (say E:\GA\EO). This will create four subfolders,

code
data
eo-1.0
epanet_tools

We use code folder to keep all the code we write (not the code libraries we use!). It already have the files:

ESEA.cpp
real_value.h

ESEA.cpp is a c++ program that can be used to access the EO Genetic algorithm functions. real_value.h has the cost function for the GA. We'll learn more about this later.

data folder where we shall keep all our data, has the water distribution network file.

eo-1.0 and epanet_tools have the evolving objects and epanet toolkit code libraries.

Solution

We shall attack our problem in a piecemeal fashion, in the steps given below:

  1. Get EO to solve a small GA problem.
  2. Replace the cost function with our own.
  3. Use epanet_toolkit to run Epanet on our water supply network and use the results to evaluate a cost function.

Usually this step-by-step approach is less error-prone than attempting the whole task once.

Running a GA

Create a new folder called projects under the same folder that has sub-folders of code, data, etc. This is where we shall keep the visual studio express edition related (platform specific) stuff. Open visual C++ and reate a new empty project EPGA in that folder. Add the following files in the code folder to the project.

 
ESEA.cpp
real_value.h