<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.heurekaslu.se/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fkl</id>
	<title>Heureka Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.heurekaslu.se/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fkl"/>
	<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/wiki/Special:Contributions/Fkl"/>
	<updated>2026-04-29T19:50:29Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4609</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4609"/>
		<updated>2010-05-24T07:33:48Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Generation  2-n */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating Treatment Programs for an analysis area ==&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;tt&amp;gt;TreatmentProgramManager&amp;lt;/tt&amp;gt; manages treatment program generation for an analysis area, as follows:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt; are evaluated and each treatment unit is assigned to a domain.&lt;br /&gt;
# For each domain:&lt;br /&gt;
## Treatment units are set aside for nature conservation&lt;br /&gt;
## For treatment units that not has been set aside, the &amp;lt;tt&amp;gt;TreatmentProgramGenerator&amp;lt;/tt&amp;gt; is called and treatment programs of the desired types (unmanaged, continuous management, or even aged management, given by the user) are generated&lt;br /&gt;
## For treatment units that has been set aside, unmanaged treatment programs are generated by the &amp;lt;tt&amp;gt;TreatmentProgramGenerator&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Treatment program generation requires is both performance and memory intensive. To get reasonable performance when reading from the database when treatment programs are generated, 20 treatment units are read at a time (or as many as there are left). Once treatment programs has been generated for a treatment unit, the memory allocated by that treatment unit is released (e.g. references are set to null allowing objects to be garbage collected).&lt;br /&gt;
&lt;br /&gt;
== Creating Continous Management and Unmanaged Treatment Programs ==&lt;br /&gt;
&lt;br /&gt;
Creating Continous Management and Unmanaged Treatment Programs is fairly trivial. Growth prognosis is done for the treatment unit until the planning horizon has been reached. &lt;br /&gt;
&lt;br /&gt;
For continous management, it is evaluated in each period if selection felling is allowed or not. If allowed, selection felling is performed.&lt;br /&gt;
&lt;br /&gt;
== Creating Even Aged Treatment Programs ==&lt;br /&gt;
&lt;br /&gt;
Creating even aged treatment programs is more complex. A number of generations of the forest has to be created (a forest generation starts with regeneration and ends with final felling). An even aged treatment program must contain at least one complete generation, even if the planning horizon is shorter (net present value cannot be calculated if not a complete generation is present).&lt;br /&gt;
&lt;br /&gt;
Even aged treatment programs are created based on treatment specifications (specifying when cleaning, first thinning, and final felling should be done) and fertilization policies (specifying if and how fertilization should be done). During the generation, a number of treatment specifications are evaluated, but the same fertilization policy is always applied for a given generation and control category. The latter also applies to regeneration.&lt;br /&gt;
&lt;br /&gt;
Each forest domain contains one or more control categories. For each control category, it is specified if the control category is to be used in generation 1, generation 2 (and forward), or both. Treatment programs will be generated for each control category in the generation being in progress.&lt;br /&gt;
&lt;br /&gt;
The diagram below illustrates the process for treatment program generation:&lt;br /&gt;
&lt;br /&gt;
[[file:tpg.png]]&lt;br /&gt;
&lt;br /&gt;
Each time regeneration is performed the treatment unit is grown until the regeneration has been activated on all prediction units (e.g. there are no waiting saplings).&lt;br /&gt;
&lt;br /&gt;
Treatment specifications will be created each time a generation is to be completed. Then a treatment program is created for each treatment specification, up to and including a final felling treatment. Then a fertilization policy is applied if required (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
Each treatment program is then checked, is the planning horizon reached and has at least one complete generation been created? If not a new generation is started. The figure above shows how new generations are simulated, there are also other (faster) possibilities to create new generations, described below.&lt;br /&gt;
&lt;br /&gt;
=== Creating Treatment Specifications ===&lt;br /&gt;
&lt;br /&gt;
A treatment specification contains a description on when cleaning, first thinning, and final felling can be done (cleaning and thinning can be omitted, final felling is always present in a treatment specification).&lt;br /&gt;
&lt;br /&gt;
The purpose of treatment specifications is to generated all possible combinations of even aged management, based on user settings and of course the state of the treatment unit.&lt;br /&gt;
&lt;br /&gt;
First it is determined when and if the treatments can be performed. For final felling lowest final felling age is calculated (according SVL, Skogsvårdslagen). For cleaning and thinning growth prognosis has to be made and in each period it is evaulated if the treatment is possible. Each treatment is then stored in a &amp;lt;tt&amp;gt;TreatmentSpecificationRange&amp;lt;/tt&amp;gt;. It may look like this:&lt;br /&gt;
&lt;br /&gt;
# Cleaning period 4-5&lt;br /&gt;
# Thinning period 8-10&lt;br /&gt;
# Final Felling period 10-14&lt;br /&gt;
&lt;br /&gt;
Thereafter the ranges are sorted in reverse priority, so that the treatment with highest priority (which will be varied most) is last. If the priority order (set by the user) is thinning - final felling - cleaning then the list above will look like this after sorting:&lt;br /&gt;
&lt;br /&gt;
# Cleaning period 4-5&lt;br /&gt;
# Final Felling period 10-14&lt;br /&gt;
# Thinning period 8-10&lt;br /&gt;
&lt;br /&gt;
The last step is to, from the ranges, create a list of possible specifications. The class &amp;lt;tt&amp;gt;TreatmentSpecificationEnumerator&amp;lt;/tt&amp;gt; creates an enumeration of all possible treatment specifications from the ranges and the class &amp;lt;tt&amp;gt;TreatmentSpecificationCollection&amp;lt;/tt&amp;gt; filters the invalid permutations.&lt;br /&gt;
&lt;br /&gt;
It might look like this:&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Cleaning||Final Felling||Thinning||Comment&lt;br /&gt;
|-&lt;br /&gt;
|4||10||8||&lt;br /&gt;
|-&lt;br /&gt;
|4||10||9||&lt;br /&gt;
|-&lt;br /&gt;
|4||10||10||Filtered since cleaning and final felling not can occur in the same period&lt;br /&gt;
|-&lt;br /&gt;
|4||11||8||&lt;br /&gt;
|-&lt;br /&gt;
|4||11||9||&lt;br /&gt;
|-&lt;br /&gt;
|4||11||10||&lt;br /&gt;
|-&lt;br /&gt;
|5||10||8||&lt;br /&gt;
|-&lt;br /&gt;
|etc&lt;br /&gt;
|}			&lt;br /&gt;
&lt;br /&gt;
(From the table it is also obvious why the treatment with the highest priority is last, it is varied most.)&lt;br /&gt;
&lt;br /&gt;
=== Creating Generation  2-n ===&lt;br /&gt;
&lt;br /&gt;
First time a second generation is created it must be simulated, but as the treatment program generates more programs for a treatment unit, treatment specifications and results from a generation are reused whenever possible, to get better performance.&lt;br /&gt;
&lt;br /&gt;
The treatment program generator tries to create as many alternatives as possible for generation 1 and 2. If more generations are needed, generation 2 is repeated, no new alternatives are created for generation 3-n.&lt;br /&gt;
&lt;br /&gt;
When a generation is finished and if it is complete (from regeneration to final felling), the treatment specification for it is saved. The treatment specifications are saved per control category, and separeted for generations that started with trees from an earlier generation (seed trees or shelterwood). The specification are sorted, with highest net present value first.&lt;br /&gt;
&lt;br /&gt;
Also, treatment programs are saved when they are complete.&lt;br /&gt;
&lt;br /&gt;
So when a new generation is to be started, the following conditions are evaluated:&lt;br /&gt;
&lt;br /&gt;
;LateGeneration: Is the generation before this generation complete? (Meaning is this generation 3 or later?)&lt;br /&gt;
;SameControlCat: Is the same control category used in the new generation as in the previous generation?&lt;br /&gt;
;SameStartState: Did the previous generation and this generation start with the same state regarding seed trees/shelterwood?&lt;br /&gt;
;SavedSpecs: Are there saved specifications for the control category to be used by the new generation, with the same state regarding seed trees/shelterwood?&lt;br /&gt;
&lt;br /&gt;
The desired methods of creating a new generation are (fastest first, slowest last):&lt;br /&gt;
&lt;br /&gt;
;CopyPreviousGeneration: Results are copied from the previous generation. No new simulation required. LateGeneration, SameControlCat, and SameStartState must be true&lt;br /&gt;
;RepeatPreviousGeneration: Specification from previous generation is used, new simulation is done. LateGeneration and SameControlCat must be true.&lt;br /&gt;
;CopyBestSaved: Several generations are created with result copied from saved treatment programs. No new simulation required. SameControlCat and SavedSpecs, and SameStartState must be true.&lt;br /&gt;
;RepeatBestSaved: Several generations are created from saved specifications. New simulations required. SameControlCat and SavedSpecs must be true.&lt;br /&gt;
;GenerateNew: Both new specifications and new simulation is done. Used when none of the methods above can be used.&lt;br /&gt;
&lt;br /&gt;
A special case occurs when the treatment program generator is invoked from StandWise. In this case the copy methods above are not allowed. This is due to the fact the copied results not are stored in the treatment unit, and diagrams and tables in StandWise only shows results from the treatment unit.&lt;br /&gt;
&lt;br /&gt;
A treatment program generation typically works like this:&lt;br /&gt;
&lt;br /&gt;
# First alternative of generation 1 is simulated.&lt;br /&gt;
## First alternative of generation 2 is simulated, specification is saved (GenerateNew)&lt;br /&gt;
### Only alternative of generation 3 (CopyPreviousGeneration)&lt;br /&gt;
## Second alternative of generation 3 is simulated, specification is saved (GenerateNew)&lt;br /&gt;
### Only alternative of generation 3 (CopyPreviousGeneration)&lt;br /&gt;
## etc for generation 2-3&lt;br /&gt;
# Second alternative of generation 1 is simulated&lt;br /&gt;
## Alternatives 1-n for generation 2 are created by coping best alternatives 1-n from first alternative of generation 1 (CopyBestSaved)&lt;br /&gt;
&lt;br /&gt;
The example above assumes that each generation either ends with retained trees, or that no generation ends with retained trees.&lt;br /&gt;
&lt;br /&gt;
If more than one control category is used the scenario gets more complex. Say that two control categories are used, SeedTrees and NoSeedTrees. Generation will then be done like this:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Generation 1||Generation 2||How is generation done?&lt;br /&gt;
|-&lt;br /&gt;
|SeedTrees||SeedTrees||As above&lt;br /&gt;
|-&lt;br /&gt;
|SeedTrees||NoSeedTrees||As above, but Repeat... instead of Copy...&lt;br /&gt;
|-&lt;br /&gt;
|NoSeedTrees||SeedTrees||As above, but Repeat... instead of Copy...&lt;br /&gt;
|-&lt;br /&gt;
|NoSeedTrees||NoSeedTrees||As above&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4599</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4599"/>
		<updated>2010-05-21T13:54:49Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Generation  2-n */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating Treatment Programs for an analysis area ==&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;tt&amp;gt;TreatmentProgramManager&amp;lt;/tt&amp;gt; manages treatment program generation for an analysis area, as follows:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt; are evaluated and each treatment unit is assigned to a domain.&lt;br /&gt;
# For each domain:&lt;br /&gt;
## Treatment units are set aside for nature conservation&lt;br /&gt;
## For treatment units that not has been set aside, the &amp;lt;tt&amp;gt;TreatmentProgramGenerator&amp;lt;/tt&amp;gt; is called and treatment programs of the desired types (unmanaged, continuous management, or even aged management, given by the user) are generated&lt;br /&gt;
## For treatment units that has been set aside, unmanaged treatment programs are generated by the &amp;lt;tt&amp;gt;TreatmentProgramGenerator&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Treatment program generation requires is both performance and memory intensive. To get reasonable performance when reading from the database when treatment programs are generated, 20 treatment units are read at a time (or as many as there are left). Once treatment programs has been generated for a treatment unit, the memory allocated by that treatment unit is released (e.g. references are set to null allowing objects to be garbage collected).&lt;br /&gt;
&lt;br /&gt;
== Creating Continous Management and Unmanaged Treatment Programs ==&lt;br /&gt;
&lt;br /&gt;
Creating Continous Management and Unmanaged Treatment Programs is fairly trivial. Growth prognosis is done for the treatment unit until the planning horizon has been reached. &lt;br /&gt;
&lt;br /&gt;
For continous management, it is evaluated in each period if selection felling is allowed or not. If allowed, selection felling is performed.&lt;br /&gt;
&lt;br /&gt;
== Creating Even Aged Treatment Programs ==&lt;br /&gt;
&lt;br /&gt;
Creating even aged treatment programs is more complex. A number of generations of the forest has to be created (a forest generation starts with regeneration and ends with final felling). An even aged treatment program must contain at least one complete generation, even if the planning horizon is shorter (net present value cannot be calculated if not a complete generation is present).&lt;br /&gt;
&lt;br /&gt;
Even aged treatment programs are created based on treatment specifications (specifying when cleaning, first thinning, and final felling should be done) and fertilization policies (specifying if and how fertilization should be done). During the generation, a number of treatment specifications are evaluated, but the same fertilization policy is always applied for a given generation and control category. The latter also applies to regeneration.&lt;br /&gt;
&lt;br /&gt;
Each forest domain contains one or more control categories. For each control category, it is specified if the control category is to be used in generation 1, generation 2 (and forward), or both. Treatment programs will be generated for each control category in the generation being in progress.&lt;br /&gt;
&lt;br /&gt;
The diagram below illustrates the process for treatment program generation:&lt;br /&gt;
&lt;br /&gt;
[[file:tpg.png]]&lt;br /&gt;
&lt;br /&gt;
Each time regeneration is performed the treatment unit is grown until the regeneration has been activated on all prediction units (e.g. there are no waiting saplings).&lt;br /&gt;
&lt;br /&gt;
Treatment specifications will be created each time a generation is to be completed. Then a treatment program is created for each treatment specification, up to and including a final felling treatment. Then a fertilization policy is applied if required (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
Each treatment program is then checked, is the planning horizon reached and has at least one complete generation been created? If not a new generation is started. The figure above shows how new generations are simulated, there are also other (faster) possibilities to create new generations, described below.&lt;br /&gt;
&lt;br /&gt;
=== Creating Treatment Specifications ===&lt;br /&gt;
&lt;br /&gt;
A treatment specification contains a description on when cleaning, first thinning, and final felling can be done (cleaning and thinning can be omitted, final felling is always present in a treatment specification).&lt;br /&gt;
&lt;br /&gt;
The purpose of treatment specifications is to generated all possible combinations of even aged management, based on user settings and of course the state of the treatment unit.&lt;br /&gt;
&lt;br /&gt;
First it is determined when and if the treatments can be performed. For final felling lowest final felling age is calculated (according SVL, Skogsvårdslagen). For cleaning and thinning growth prognosis has to be made and in each period it is evaulated if the treatment is possible. Each treatment is then stored in a &amp;lt;tt&amp;gt;TreatmentSpecificationRange&amp;lt;/tt&amp;gt;. It may look like this:&lt;br /&gt;
&lt;br /&gt;
# Cleaning period 4-5&lt;br /&gt;
# Thinning period 8-10&lt;br /&gt;
# Final Felling period 10-14&lt;br /&gt;
&lt;br /&gt;
Thereafter the ranges are sorted in reverse priority, so that the treatment with highest priority (which will be varied most) is last. If the priority order (set by the user) is thinning - final felling - cleaning then the list above will look like this after sorting:&lt;br /&gt;
&lt;br /&gt;
# Cleaning period 4-5&lt;br /&gt;
# Final Felling period 10-14&lt;br /&gt;
# Thinning period 8-10&lt;br /&gt;
&lt;br /&gt;
The last step is to, from the ranges, create a list of possible specifications. The class &amp;lt;tt&amp;gt;TreatmentSpecificationEnumerator&amp;lt;/tt&amp;gt; creates an enumeration of all possible treatment specifications from the ranges and the class &amp;lt;tt&amp;gt;TreatmentSpecificationCollection&amp;lt;/tt&amp;gt; filters the invalid permutations.&lt;br /&gt;
&lt;br /&gt;
It might look like this:&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Cleaning||Final Felling||Thinning||Comment&lt;br /&gt;
|-&lt;br /&gt;
|4||10||8||&lt;br /&gt;
|-&lt;br /&gt;
|4||10||9||&lt;br /&gt;
|-&lt;br /&gt;
|4||10||10||Filtered since cleaning and final felling not can occur in the same period&lt;br /&gt;
|-&lt;br /&gt;
|4||11||8||&lt;br /&gt;
|-&lt;br /&gt;
|4||11||9||&lt;br /&gt;
|-&lt;br /&gt;
|4||11||10||&lt;br /&gt;
|-&lt;br /&gt;
|5||10||8||&lt;br /&gt;
|-&lt;br /&gt;
|etc&lt;br /&gt;
|}			&lt;br /&gt;
&lt;br /&gt;
(From the table it is also obvious why the treatment with the highest priority is last, it is varied most.)&lt;br /&gt;
&lt;br /&gt;
=== Creating Generation  2-n ===&lt;br /&gt;
&lt;br /&gt;
First time a second generation is created it must be simulated, but as the treatment program generates more programs for a treatment unit, treatment specifications and results from a generation can be reused to get better performance.&lt;br /&gt;
&lt;br /&gt;
When a generation is finished and if it is complete (from regeneration to final felling), the treatment specification for it is saved. The treatment specifications are saved per control category, and separeted for generations that started with trees from an earlier generation (seed trees or shelterwood). The specification are sorted, with highest net present value first.&lt;br /&gt;
&lt;br /&gt;
Also, treatment programs are saved when they are complete.&lt;br /&gt;
&lt;br /&gt;
So when a new generation is to be started, the following conditions are evaluated:&lt;br /&gt;
&lt;br /&gt;
;LateGeneration: Is the generation before this generation complete? (Meaning is this generation 3 or later?)&lt;br /&gt;
;SameControlCat: Is the same control category used in the new generation as in the previous generation?&lt;br /&gt;
;SameStartState: Did the previous generation and this generation start with the same state regarding seed trees/shelterwood?&lt;br /&gt;
;SavedSpecs: Are there saved specifications for the control category to be used by the new generation, with the same state regarding seed trees/shelterwood?&lt;br /&gt;
&lt;br /&gt;
The desired methods of creating a new generation are (fastest first, slowest last):&lt;br /&gt;
&lt;br /&gt;
;CopyPreviousGeneration: Results are copied from the previous generation. No new simulation required. LateGeneration, SameControlCat, and SameStartState must be true&lt;br /&gt;
;RepeatPreviousGeneration: Specification from previous generation is used, new simulation is done. LateGeneration and SameControlCat must be true.&lt;br /&gt;
;CopyBestSaved: Several generations are created with result copied from saved treatment programs. No new simulation required. SameControlCat and SavedSpecs, and SameStartState must be true.&lt;br /&gt;
;RepeatBestSaved: Several generations are created from saved specifications. New simulations required. SameControlCat and SavedSpecs must be true.&lt;br /&gt;
;GenerateNew: Both new specifications and new simulation is done.&lt;br /&gt;
&lt;br /&gt;
A special case occurs when the treatment program generator is invoked from StandWise. In this case the copy methods above are not allowed. This is due to the fact the copied results not are stored in the treatment unit, and diagrams and tables in StandWise only shows results from the treatment unit.&lt;br /&gt;
&lt;br /&gt;
A treatment program generation typically works like this:&lt;br /&gt;
&lt;br /&gt;
# First alternative of generation 1 is simulated.&lt;br /&gt;
## GenerateNew First alternative of generation 2 is simulated, specification is saved&lt;br /&gt;
### CopyPreviousGeneration&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4598</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4598"/>
		<updated>2010-05-21T13:32:09Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Treatment Specifications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4597</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4597"/>
		<updated>2010-05-21T13:04:29Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Even Aged Treatment Programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=File:Tpg.png&amp;diff=4596</id>
		<title>File:Tpg.png</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=File:Tpg.png&amp;diff=4596"/>
		<updated>2010-05-21T12:59:02Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4595</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4595"/>
		<updated>2010-05-21T12:44:33Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Continous Management and Unmanaged Treatment Programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4594</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4594"/>
		<updated>2010-05-21T12:41:59Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating Treatment Programs for an analysis area */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4593</id>
		<title>Treatment Program Generator Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Treatment_Program_Generator_Design&amp;diff=4593"/>
		<updated>2010-05-21T12:34:54Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Treatment_Models&amp;diff=4592</id>
		<title>Design of Treatment Models</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Treatment_Models&amp;diff=4592"/>
		<updated>2010-05-21T12:29:58Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Felling Treatments ==&lt;br /&gt;
&lt;br /&gt;
Felling treatments, e.g. final felling, thinning, and selection felling are fairly simple once the intensity of the treatment has been determined per tree. All that has to be done is to adjust &amp;lt;tt&amp;gt;StemsResidual&amp;lt;/tt&amp;gt; for each affected tree.&lt;br /&gt;
&lt;br /&gt;
== Regeneration including soil preperation ==&lt;br /&gt;
&lt;br /&gt;
The regeneration models are fairly complex, for more details about the models see [[Regeneration]].&lt;br /&gt;
&lt;br /&gt;
Both the existing regeneration simulators (the &amp;lt;tt&amp;gt;ModelRegenerationSimulator&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;DatabaseRegenerationSimulator&amp;lt;/tt&amp;gt; produces a list of saplings that are to be activated in a future period. This is implemented as follows, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# The saplings are added to the trees of the prediction unit, with the desired state of the sapling in the current period&lt;br /&gt;
# The activation period is determined&lt;br /&gt;
# The regeneration period is determined (this does not necessarily have to be the current period, depending on the fallow period, i.e. minimum number of years between final felling and regeneration)&lt;br /&gt;
# The expected state for each tree between from the regeneration period to (but not including) the activation period is calculated with interpolation&lt;br /&gt;
# The state of the current period for each tree is moved to the activation period&lt;br /&gt;
# The state of each period from period 0 to but not including the regeneration period is set (all values are 0 and all trees are invalid)&lt;br /&gt;
# Diameter and height growth for each period is set for each tree (as the state of each period is known growth can easily be calculated)&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4591</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4591"/>
		<updated>2010-05-21T12:05:17Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Growing for other period lengths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that are treatment related&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# If there are saplings but not waiting saplings, and mean height exceeds height limit for young stand, change saplings to trees:&lt;br /&gt;
## Change tree type of saplings with diameter &amp;lt; 4 cm to removed&lt;br /&gt;
## Change tree type of remaining saplings to trees&lt;br /&gt;
## Update aggregated values for each prediction unit where there was saplings&lt;br /&gt;
# If there are ingrown trees:&lt;br /&gt;
## Assign age, height, and growth to each ingrown tree&lt;br /&gt;
## Update aggregated values for each prediction unit where there was ingrown trees&lt;br /&gt;
# If aggregated values for any prediction unit has been changed, update aggregated values for the treatment unit&lt;br /&gt;
# Perform growth adjustment that is not treatment related&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
For each prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Height and volume is assigned to trees&lt;br /&gt;
# Volume is assigned to saplings&lt;br /&gt;
# If first period, dead trees is estimated&lt;br /&gt;
# Aggregated volume is updated&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
=== When are growth adjusters called and why? ===&lt;br /&gt;
&lt;br /&gt;
Certain treatments and models may affect the forest state a long time after the treatment has occured or the model was activated. For instance, doing a final felling with seed trees also requires that the seed trees are removed after some time, extracting biofuel causes a growth reduction, intensive fertilization causes increased growth.&lt;br /&gt;
&lt;br /&gt;
To solve this problem, it is possible to register a &amp;lt;tt&amp;gt;IGrowthAdjuster&amp;lt;/tt&amp;gt; to a treatment unit. &lt;br /&gt;
&lt;br /&gt;
Registered growth adjusters are called two times during growth prognosis:&lt;br /&gt;
&lt;br /&gt;
;&amp;quot;BeforeTreatment&amp;quot;: Just after the state in a new period has been calculated, but before height and volume has been calculated&lt;br /&gt;
;&amp;quot;AfterTreatment&amp;quot;: After height and volume has been calculated&lt;br /&gt;
&lt;br /&gt;
(The terms BeforeTreatment and AfterTreatment are not so descriptive, but will be explained more below.)&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;IGrowthAdjuster&amp;lt;/tt&amp;gt; must decide if it should be applied BeforeTreatment, or AfterTreatment.&lt;br /&gt;
&lt;br /&gt;
BeforeTreatment is used if the adjustment is due to an expected growth change caused by the treatment. For instance, extraction of biofuel or intensive fertilization adjusts the growth and this will also affect volume, height, and the state before treatment for the new period. '''Growth adjusters that has BeforeTreatment set to true are those that affects the state ''before'' treatment for the new period'''&lt;br /&gt;
&lt;br /&gt;
AfterTreatment is used if the adjustment is due to an extra treatment being automatically invoked in the new period. For instance, removal of overstorey trees. '''Growth adjusters that has BeforeTreatment set to false are those that affects the state after treatment for the new period'''&lt;br /&gt;
&lt;br /&gt;
=== Implementing a growth adjuster ===&lt;br /&gt;
&lt;br /&gt;
A growth adjuster typically stores a period or a period range internally to know when to do the adjustment. For example, the &amp;lt;tt&amp;gt;OverstoreyRemover&amp;lt;/tt&amp;gt; class stores the removal period. When &amp;lt;tt&amp;gt;AdjustGrowth&amp;lt;/tt&amp;gt; is called, it can then check if the current period is the removal period, and then remove the overstorey layer.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Remarks ===&lt;br /&gt;
&lt;br /&gt;
Growth adjusters has proven to be powerful when implementing certain types of treatments, but also hard to understand. An alternative solution would be to define events on the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; class, and allow other classes register to those events. Suggested events are:&lt;br /&gt;
&lt;br /&gt;
;GrowthCalculated:Occurs when growth prognosis has been made, but before a new period is entered. This allows classes like the &amp;lt;tt&amp;gt;BioFuelGrowthAdjuster&amp;lt;/tt&amp;gt; to make further adjustments to the growth prognosis.&lt;br /&gt;
;NewPeriodEntered:Occurs when the state of a new period has been calculated, but before any other calculations (such as volume and height) in the new period. This allows classes like the &amp;lt;tt&amp;gt;IntensiveFertilizor&amp;lt;/tt&amp;gt; to adjust variables like site index in the new period.&lt;br /&gt;
;GrowthComplete:Occurs when the growth calculcation is complete. This can be used by most existing growth adjusters, to perform additional treatments for instance.&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;br /&gt;
&lt;br /&gt;
Growing for other period lengths than 5 years is done by first growing a normal 5-year period, and then interpolate the values to the desired length.&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4590</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4590"/>
		<updated>2010-05-21T12:04:15Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Making growth adjustments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that are treatment related&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# If there are saplings but not waiting saplings, and mean height exceeds height limit for young stand, change saplings to trees:&lt;br /&gt;
## Change tree type of saplings with diameter &amp;lt; 4 cm to removed&lt;br /&gt;
## Change tree type of remaining saplings to trees&lt;br /&gt;
## Update aggregated values for each prediction unit where there was saplings&lt;br /&gt;
# If there are ingrown trees:&lt;br /&gt;
## Assign age, height, and growth to each ingrown tree&lt;br /&gt;
## Update aggregated values for each prediction unit where there was ingrown trees&lt;br /&gt;
# If aggregated values for any prediction unit has been changed, update aggregated values for the treatment unit&lt;br /&gt;
# Perform growth adjustment that is not treatment related&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
For each prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Height and volume is assigned to trees&lt;br /&gt;
# Volume is assigned to saplings&lt;br /&gt;
# If first period, dead trees is estimated&lt;br /&gt;
# Aggregated volume is updated&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
=== When are growth adjusters called and why? ===&lt;br /&gt;
&lt;br /&gt;
Certain treatments and models may affect the forest state a long time after the treatment has occured or the model was activated. For instance, doing a final felling with seed trees also requires that the seed trees are removed after some time, extracting biofuel causes a growth reduction, intensive fertilization causes increased growth.&lt;br /&gt;
&lt;br /&gt;
To solve this problem, it is possible to register a &amp;lt;tt&amp;gt;IGrowthAdjuster&amp;lt;/tt&amp;gt; to a treatment unit. &lt;br /&gt;
&lt;br /&gt;
Registered growth adjusters are called two times during growth prognosis:&lt;br /&gt;
&lt;br /&gt;
;&amp;quot;BeforeTreatment&amp;quot;: Just after the state in a new period has been calculated, but before height and volume has been calculated&lt;br /&gt;
;&amp;quot;AfterTreatment&amp;quot;: After height and volume has been calculated&lt;br /&gt;
&lt;br /&gt;
(The terms BeforeTreatment and AfterTreatment are not so descriptive, but will be explained more below.)&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;IGrowthAdjuster&amp;lt;/tt&amp;gt; must decide if it should be applied BeforeTreatment, or AfterTreatment.&lt;br /&gt;
&lt;br /&gt;
BeforeTreatment is used if the adjustment is due to an expected growth change caused by the treatment. For instance, extraction of biofuel or intensive fertilization adjusts the growth and this will also affect volume, height, and the state before treatment for the new period. '''Growth adjusters that has BeforeTreatment set to true are those that affects the state ''before'' treatment for the new period'''&lt;br /&gt;
&lt;br /&gt;
AfterTreatment is used if the adjustment is due to an extra treatment being automatically invoked in the new period. For instance, removal of overstorey trees. '''Growth adjusters that has BeforeTreatment set to false are those that affects the state after treatment for the new period'''&lt;br /&gt;
&lt;br /&gt;
=== Implementing a growth adjuster ===&lt;br /&gt;
&lt;br /&gt;
A growth adjuster typically stores a period or a period range internally to know when to do the adjustment. For example, the &amp;lt;tt&amp;gt;OverstoreyRemover&amp;lt;/tt&amp;gt; class stores the removal period. When &amp;lt;tt&amp;gt;AdjustGrowth&amp;lt;/tt&amp;gt; is called, it can then check if the current period is the removal period, and then remove the overstorey layer.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Remarks ===&lt;br /&gt;
&lt;br /&gt;
Growth adjusters has proven to be powerful when implementing certain types of treatments, but also hard to understand. An alternative solution would be to define events on the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; class, and allow other classes register to those events. Suggested events are:&lt;br /&gt;
&lt;br /&gt;
;GrowthCalculated:Occurs when growth prognosis has been made, but before a new period is entered. This allows classes like the &amp;lt;tt&amp;gt;BioFuelGrowthAdjuster&amp;lt;/tt&amp;gt; to make further adjustments to the growth prognosis.&lt;br /&gt;
;NewPeriodEntered:Occurs when the state of a new period has been calculated, but before any other calculations (such as volume and height) in the new period. This allows classes like the &amp;lt;tt&amp;gt;IntensiveFertilizor&amp;lt;/tt&amp;gt; to adjust variables like site index in the new period.&lt;br /&gt;
;GrowthComplete:Occurs when the growth calculcation is complete. This can be used by most existing growth adjusters, to perform additional treatments for instance.&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4589</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4589"/>
		<updated>2010-05-21T11:24:58Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Assigning height and volume */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that are treatment related&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# If there are saplings but not waiting saplings, and mean height exceeds height limit for young stand, change saplings to trees:&lt;br /&gt;
## Change tree type of saplings with diameter &amp;lt; 4 cm to removed&lt;br /&gt;
## Change tree type of remaining saplings to trees&lt;br /&gt;
## Update aggregated values for each prediction unit where there was saplings&lt;br /&gt;
# If there are ingrown trees:&lt;br /&gt;
## Assign age, height, and growth to each ingrown tree&lt;br /&gt;
## Update aggregated values for each prediction unit where there was ingrown trees&lt;br /&gt;
# If aggregated values for any prediction unit has been changed, update aggregated values for the treatment unit&lt;br /&gt;
# Perform growth adjustment that is not treatment related&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
For each prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Height and volume is assigned to trees&lt;br /&gt;
# Volume is assigned to saplings&lt;br /&gt;
# If first period, dead trees is estimated&lt;br /&gt;
# Aggregated volume is updated&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4588</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4588"/>
		<updated>2010-05-21T11:17:45Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that are treatment related&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# If there are saplings but not waiting saplings, and mean height exceeds height limit for young stand, change saplings to trees:&lt;br /&gt;
## Change tree type of saplings with diameter &amp;lt; 4 cm to removed&lt;br /&gt;
## Change tree type of remaining saplings to trees&lt;br /&gt;
## Update aggregated values for each prediction unit where there was saplings&lt;br /&gt;
# If there are ingrown trees:&lt;br /&gt;
## Assign age, height, and growth to each ingrown tree&lt;br /&gt;
## Update aggregated values for each prediction unit where there was ingrown trees&lt;br /&gt;
# If aggregated values for any prediction unit has been changed, update aggregated values for the treatment unit&lt;br /&gt;
# Perform growth adjustment that is not treatment related&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4587</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4587"/>
		<updated>2010-05-21T11:17:00Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Calculate state in a new period */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that should occur before treatment, if required&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# If there are saplings but not waiting saplings, and mean height exceeds height limit for young stand, change saplings to trees:&lt;br /&gt;
## Change tree type of saplings with diameter &amp;lt; 4 cm to removed&lt;br /&gt;
## Change tree type of remaining saplings to trees&lt;br /&gt;
## Update aggregated values for each prediction unit where there was saplings&lt;br /&gt;
# If there are ingrown trees:&lt;br /&gt;
## Assign age, height, and growth to each ingrown tree&lt;br /&gt;
## Update aggregated values for each prediction unit where there was ingrown trees&lt;br /&gt;
# If aggregated values for any prediction unit has been changed, update aggregated values for the treatment unit&lt;br /&gt;
# Perform growth adjustment that is not treatment related&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4586</id>
		<title>Calculation of growth</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Calculation_of_growth&amp;diff=4586"/>
		<updated>2010-05-21T09:52:53Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Growth from one period to another period is done as follows (assuming 5-year periods)&lt;br /&gt;
&lt;br /&gt;
# Make a growth prognosis based on the residual state (state after treatment, if any) of the treatment unit&lt;br /&gt;
# Calculate the state in the new period&lt;br /&gt;
# Assign height and volume to trees in the new period (based on the state before treatment in the new period)&lt;br /&gt;
# Make growth adjustments that should occur before treatment, if required&lt;br /&gt;
&lt;br /&gt;
== Make growth prognosis ==&lt;br /&gt;
&lt;br /&gt;
Growth prognosis is done in the following steps, per prediction unit:&lt;br /&gt;
&lt;br /&gt;
# Update tree values&lt;br /&gt;
## Determine Bal for each tree (basal area of all larger trees)&lt;br /&gt;
## Determine if each tree is an overstorey tree or not&lt;br /&gt;
## If any tree changed to/from overstorey, update aggregated values for the prediction unit (e.g. mean age, total volume, and mean diameter), since some of these values are per forest layer&lt;br /&gt;
# Assign diameter growth and mortality to trees&lt;br /&gt;
# Assign height growth and mortality to saplings&lt;br /&gt;
# Prognos ingrowth (only if stand is established)&lt;br /&gt;
# Adjust diameter growth due to stand growth model and thinning effect&lt;br /&gt;
&lt;br /&gt;
== Calculate state in a new period ==&lt;br /&gt;
&lt;br /&gt;
# Set the values for the new period:&lt;br /&gt;
## Update diameter (for trees) or height (for saplings), and stems (for both trees and saplings)&lt;br /&gt;
# &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Assigning height and volume ==&lt;br /&gt;
&lt;br /&gt;
== Making growth adjustments ==&lt;br /&gt;
&lt;br /&gt;
== Growing for other period lengths ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4585</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4585"/>
		<updated>2010-05-21T09:29:02Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Forest model and Calculations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of [[Design of Treatment Models|treatment models]] such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a [[Calculation of growth|treatment unit can grow]], i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot (Riksskogstaxeringen). In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder |SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
Note that for the result database, custom OR-mapping is used. The result database are created automatically based on the [[Result Models]] in the system, and existing result databases will automatically be extended if new result variables and models are introduced in later versions of the system. Queries against the result database are created by SQL queries generated with reflection from the result models.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used.&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Handling_of_tree_states&amp;diff=4584</id>
		<title>Handling of tree states</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Handling_of_tree_states&amp;diff=4584"/>
		<updated>2010-05-21T09:13:01Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Adding new Trees */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tree States ==&lt;br /&gt;
&lt;br /&gt;
Each tree may have one of the following states:&lt;br /&gt;
;Tree: Establised tree&lt;br /&gt;
;IngrownTree: A tree that just has been ingrown.&lt;br /&gt;
;Sapling: Sapling&lt;br /&gt;
;WatingTree: Tree waiting to be activated. This means that the future state of the tree has been calculated, and growth for the tree should not be calculated in growth prognosis. Waiting trees might be felled.&lt;br /&gt;
;WaitingSapling: Sapling waiting to be activated. This is similar to waiting trees. However, waiting saplings cannot be cleaned.&lt;br /&gt;
;RemovedTree:Tree that is dead&lt;br /&gt;
;InvalidTree:Tree that is invalid. A tree can be removed if it is invalid in the current period.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; has a state before treatment, &amp;lt;tt&amp;gt;TreeCategory&amp;lt;/tt&amp;gt;, and after treatment, &amp;lt;tt&amp;gt;TreeCategoryResidual&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Sorting Trees ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;TreeCollection&amp;lt;/tt&amp;gt; class keeps trees sorted in the current period. This makes it easy and fast to iterate over trees with a certain state, since all those trees are kept together.&lt;br /&gt;
&lt;br /&gt;
== Adding new Trees ==&lt;br /&gt;
&lt;br /&gt;
Both the ingrowth model and the regeneration models creates and adds new &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt;s to a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Say that the regeneration model runs in period 2, and the saplings are to be activated in period 4. A &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; object would then have the following states for each period (before and after treatment, Residual State is state after treatment):&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Period||width=&amp;quot;120pt&amp;quot;|0||width=&amp;quot;120pt&amp;quot;|1||width=&amp;quot;120pt&amp;quot;|2||width=&amp;quot;120pt&amp;quot;|3||width=&amp;quot;120pt&amp;quot;|4||width=&amp;quot;120pt&amp;quot;|5&lt;br /&gt;
|-&lt;br /&gt;
|State||Invalid||Invalid||Invalid||Waiting Sapling||Waiting Sapling||Sapling&lt;br /&gt;
|-&lt;br /&gt;
|Residual State||Invalid||Invalid||Waiting Sapling||Waiting Sapling||Sapling||Sapling&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This means that:&lt;br /&gt;
&lt;br /&gt;
* If current period of the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; is changed back to period 0, 1, or 2 the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; object will be removed, since its state is invalid.&lt;br /&gt;
* If current period is 3 or 4, growth of the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; shall not be calculated, since the state WaitingSapling indicates that the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; already has a calculated future state.&lt;br /&gt;
* If current period is 5, growth of the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; shall be calculated, using height growth model for saplings. The &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; may also be cleaned since it represents a sapling.&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Handling_of_tree_states&amp;diff=4583</id>
		<title>Handling of tree states</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Handling_of_tree_states&amp;diff=4583"/>
		<updated>2010-05-21T09:12:46Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Adding new Trees */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tree States ==&lt;br /&gt;
&lt;br /&gt;
Each tree may have one of the following states:&lt;br /&gt;
;Tree: Establised tree&lt;br /&gt;
;IngrownTree: A tree that just has been ingrown.&lt;br /&gt;
;Sapling: Sapling&lt;br /&gt;
;WatingTree: Tree waiting to be activated. This means that the future state of the tree has been calculated, and growth for the tree should not be calculated in growth prognosis. Waiting trees might be felled.&lt;br /&gt;
;WaitingSapling: Sapling waiting to be activated. This is similar to waiting trees. However, waiting saplings cannot be cleaned.&lt;br /&gt;
;RemovedTree:Tree that is dead&lt;br /&gt;
;InvalidTree:Tree that is invalid. A tree can be removed if it is invalid in the current period.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; has a state before treatment, &amp;lt;tt&amp;gt;TreeCategory&amp;lt;/tt&amp;gt;, and after treatment, &amp;lt;tt&amp;gt;TreeCategoryResidual&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Sorting Trees ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;TreeCollection&amp;lt;/tt&amp;gt; class keeps trees sorted in the current period. This makes it easy and fast to iterate over trees with a certain state, since all those trees are kept together.&lt;br /&gt;
&lt;br /&gt;
== Adding new Trees ==&lt;br /&gt;
&lt;br /&gt;
Both the ingrowth model and the regeneration models creates and adds new &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt;s to a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Say that the regeneration model runs in period 2, and the saplings are to be activated in period 4. A &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; object would then have the following states for each period (before and after treatment, Residual State is state after treatment):&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Period||width=&amp;quot;120pt&amp;quot;|0||width=&amp;quot;120pt&amp;quot;|1||width=&amp;quot;120pt&amp;quot;|2||width=&amp;quot;120pt&amp;quot;|3||width=&amp;quot;120pt&amp;quot;|4||width=&amp;quot;120pt&amp;quot;|5&lt;br /&gt;
|-&lt;br /&gt;
|State||Invalid||Invalid||Invalid||Waiting Sapling||Waiting Sapling||Sapling&lt;br /&gt;
|-&lt;br /&gt;
|Residual State||Invalid||Invalid||Waiting Sapling||Waiting Sapling||Sapling||Sapling&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This means that:&lt;br /&gt;
&lt;br /&gt;
* If current period of the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; is changed back to period 0, 1, or 2 the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; object will be removed, since its state is invalid.&lt;br /&gt;
* If current period is 3, growth of the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; shall not be calculated, since the state WaitingSapling indicates that the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; already has a calculated future state.&lt;br /&gt;
* If current period is 4, growth of the &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; shall be calculated, using height growth model for saplings. The &amp;lt;tt&amp;gt;Tree&amp;lt;/tt&amp;gt; may also be cleaned since it represents a sapling.&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4582</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4582"/>
		<updated>2010-05-21T09:08:09Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Persisting Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot (Riksskogstaxeringen). In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder |SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
Note that for the result database, custom OR-mapping is used. The result database are created automatically based on the [[Result Models]] in the system, and existing result databases will automatically be extended if new result variables and models are introduced in later versions of the system. Queries against the result database are created by SQL queries generated with reflection from the result models.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used.&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4581</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4581"/>
		<updated>2010-05-21T09:06:50Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Persisting Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot (Riksskogstaxeringen). In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
Note that for the result database, custom OR-mapping is used. The result database are created automatically based on the [[Result Models]] in the system, and existing result databases will automatically be extended if new result variables and models are introduced in later versions of the system. Queries against the result database are created by SQL queries generated with reflection from the result models.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used.&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4580</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4580"/>
		<updated>2010-05-21T09:03:47Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Data Import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot (Riksskogstaxeringen). In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used.&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4579</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4579"/>
		<updated>2010-05-21T09:02:33Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Serialization and Deserialization of Control Tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; inherits from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;, it is easy to hide properties conditionally. Two protected methods can be overriden to hide properties:&lt;br /&gt;
&lt;br /&gt;
;GetCategoryNamesToHide:Gets names of entire categories to be hidden&lt;br /&gt;
;GetPropertyNamesToHide:Gets names of properties to be hidden&lt;br /&gt;
&lt;br /&gt;
Each time the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is rendered, these two methods are called, and any returned category or property will be hidden from the user.&lt;br /&gt;
&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
Sometimes simple types are not convenient in a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, and a special class is developed to hold the configuration. There are several considerations when making such a class:&lt;br /&gt;
&lt;br /&gt;
# The class must be serializable&lt;br /&gt;
# The class must be clonable&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must have one or more properties with the type of the class&lt;br /&gt;
# When the control table is cloned, each property with the custom type class must also be cloned&lt;br /&gt;
# The class may have a custom editor. To use the custom editor, set the Editor attribute for each property&lt;br /&gt;
# Changes in the custom object must trigger the &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; event:&lt;br /&gt;
## If the entire object is changed, it is sufficient to just send the event from the property of the ControlTable (typically this works fine&lt;br /&gt;
for custom classes with editors)&lt;br /&gt;
## If a property is changed inside the object the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must listen for &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; from the object, and propagate the event.&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must implement &amp;lt;tt&amp;gt;IClonable&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Don't forget to clone reference types (e.g. custom classes inside the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* If inheriting from another &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, make sure that the &amp;lt;tt&amp;gt;base.Clone()&amp;lt;/tt&amp;gt; is called.&lt;br /&gt;
&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
It is possible to extend a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; by inheriting from it. When &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are loaded automatically, only the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; lowest in the inheritance hierarchy will be loaded.&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4578</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4578"/>
		<updated>2010-05-21T09:02:12Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Extending Control Tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; inherits from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;, it is easy to hide properties conditionally. Two protected methods can be overriden to hide properties:&lt;br /&gt;
&lt;br /&gt;
;GetCategoryNamesToHide:Gets names of entire categories to be hidden&lt;br /&gt;
;GetPropertyNamesToHide:Gets names of properties to be hidden&lt;br /&gt;
&lt;br /&gt;
Each time the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is rendered, these two methods are called, and any returned category or property will be hidden from the user.&lt;br /&gt;
&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
Sometimes simple types are not convenient in a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, and a special class is developed to hold the configuration. There are several considerations when making such a class:&lt;br /&gt;
&lt;br /&gt;
# The class must be serializable&lt;br /&gt;
# The class must be clonable&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must have one or more properties with the type of the class&lt;br /&gt;
# When the control table is cloned, each property with the custom type class must also be cloned&lt;br /&gt;
# The class may have a custom editor. To use the custom editor, set the Editor attribute for each property&lt;br /&gt;
# Changes in the custom object must trigger the &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; event:&lt;br /&gt;
## If the entire object is changed, it is sufficient to just send the event from the property of the ControlTable (typically this works fine&lt;br /&gt;
for custom classes with editors)&lt;br /&gt;
## If a property is changed inside the object the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must listen for &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; from the object, and propagate the event.&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must implement &amp;lt;tt&amp;gt;IClonable&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Don't forget to clone reference types (e.g. custom classes inside the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* If inheriting from another &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, make sure that the &amp;lt;tt&amp;gt;base.Clone()&amp;lt;/tt&amp;gt; is called.&lt;br /&gt;
&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
It is possible to extend a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; by inheriting from it. When &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are loaded automatically, only the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; lowest in the inheritance hierarchy will be loaded.&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4577</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4577"/>
		<updated>2010-05-21T09:00:40Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Cloning Control Tables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; inherits from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;, it is easy to hide properties conditionally. Two protected methods can be overriden to hide properties:&lt;br /&gt;
&lt;br /&gt;
;GetCategoryNamesToHide:Gets names of entire categories to be hidden&lt;br /&gt;
;GetPropertyNamesToHide:Gets names of properties to be hidden&lt;br /&gt;
&lt;br /&gt;
Each time the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is rendered, these two methods are called, and any returned category or property will be hidden from the user.&lt;br /&gt;
&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
Sometimes simple types are not convenient in a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, and a special class is developed to hold the configuration. There are several considerations when making such a class:&lt;br /&gt;
&lt;br /&gt;
# The class must be serializable&lt;br /&gt;
# The class must be clonable&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must have one or more properties with the type of the class&lt;br /&gt;
# When the control table is cloned, each property with the custom type class must also be cloned&lt;br /&gt;
# The class may have a custom editor. To use the custom editor, set the Editor attribute for each property&lt;br /&gt;
# Changes in the custom object must trigger the &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; event:&lt;br /&gt;
## If the entire object is changed, it is sufficient to just send the event from the property of the ControlTable (typically this works fine&lt;br /&gt;
for custom classes with editors)&lt;br /&gt;
## If a property is changed inside the object the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must listen for &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; from the object, and propagate the event.&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must implement &amp;lt;tt&amp;gt;IClonable&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Don't forget to clone reference types (e.g. custom classes inside the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* If inheriting from another &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, make sure that the &amp;lt;tt&amp;gt;base.Clone()&amp;lt;/tt&amp;gt; is called.&lt;br /&gt;
&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4576</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4576"/>
		<updated>2010-05-21T08:58:39Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Using Custom Classes inside a Control Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; inherits from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;, it is easy to hide properties conditionally. Two protected methods can be overriden to hide properties:&lt;br /&gt;
&lt;br /&gt;
;GetCategoryNamesToHide:Gets names of entire categories to be hidden&lt;br /&gt;
;GetPropertyNamesToHide:Gets names of properties to be hidden&lt;br /&gt;
&lt;br /&gt;
Each time the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is rendered, these two methods are called, and any returned category or property will be hidden from the user.&lt;br /&gt;
&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
Sometimes simple types are not convenient in a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, and a special class is developed to hold the configuration. There are several considerations when making such a class:&lt;br /&gt;
&lt;br /&gt;
# The class must be serializable&lt;br /&gt;
# The class must be clonable&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must have one or more properties with the type of the class&lt;br /&gt;
# When the control table is cloned, each property with the custom type class must also be cloned&lt;br /&gt;
# The class may have a custom editor. To use the custom editor, set the Editor attribute for each property&lt;br /&gt;
# Changes in the custom object must trigger the &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; event:&lt;br /&gt;
## If the entire object is changed, it is sufficient to just send the event from the property of the ControlTable (typically this works fine&lt;br /&gt;
for custom classes with editors)&lt;br /&gt;
## If a property is changed inside the object the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; must listen for &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; from the object, and propagate the event.&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4575</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4575"/>
		<updated>2010-05-21T08:40:44Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Hiding Properties Conditionally */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; inherits from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;, it is easy to hide properties conditionally. Two protected methods can be overriden to hide properties:&lt;br /&gt;
&lt;br /&gt;
;GetCategoryNamesToHide:Gets names of entire categories to be hidden&lt;br /&gt;
;GetPropertyNamesToHide:Gets names of properties to be hidden&lt;br /&gt;
&lt;br /&gt;
Each time the &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is rendered, these two methods are called, and any returned category or property will be hidden from the user.&lt;br /&gt;
&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4574</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4574"/>
		<updated>2010-05-21T08:35:52Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Creating a new Control Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVariation must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NoInlining&amp;lt;/tt&amp;gt; must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for the most common simple types.&lt;br /&gt;
&lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4573</id>
		<title>Design of Control Tables</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Design_of_Control_Tables&amp;diff=4573"/>
		<updated>2010-05-21T07:53:09Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is a class whose instances can hold user settings. &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are typically presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, which means that no user interface has to be built for properties with a simple type.&lt;br /&gt;
&lt;br /&gt;
By adding the sttribute &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable&amp;lt;/tt&amp;gt; a class is marked as a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;. The system will automatically discover all &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; at startup.&lt;br /&gt;
&lt;br /&gt;
== Implementation of Control Tables ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a new Control Table ===&lt;br /&gt;
&lt;br /&gt;
Although not required, it is recommended that &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; inherit from &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt;. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To add a property of a simple type, follow this example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
public int CleaningVariation&lt;br /&gt;
{&lt;br /&gt;
    get { return _cleaningVariation; }&lt;br /&gt;
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]&lt;br /&gt;
    set&lt;br /&gt;
    {&lt;br /&gt;
        if (value &amp;lt; 0)&lt;br /&gt;
            throw new ArgumentOutOfRangeException(&amp;quot;value&amp;quot;, &amp;quot;CleaningVar must be &amp;gt;= 0&amp;quot;);&lt;br /&gt;
        ChangeProperty(ref _cleaningVariation, value);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
&lt;br /&gt;
* NoInlining must be set for the set method, otherwise property changed won't work in release mode&lt;br /&gt;
* Validation can be done before the value is changed&lt;br /&gt;
* &amp;lt;tt&amp;gt;UndoablePropertyChangedBase&amp;lt;/tt&amp;gt; implements &amp;lt;tt&amp;gt;ChangeProperty&amp;lt;/tt&amp;gt; methods with overloads for &lt;br /&gt;
=== Presentation of Control Tables ===&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt; are presented in a &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;, the attributes in &amp;lt;tt&amp;gt;System.ComponentModel&amp;lt;/tt&amp;gt; aids with the presentation of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt;, such as:&lt;br /&gt;
&lt;br /&gt;
;Category: Properties with the same Category are grouped in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;&lt;br /&gt;
;DisplayName: The DisplayName is the name for the property shown in the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
;Description: The Description is shown at the bottom of the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; when the property is selected. The description should give a brief help to the user.&lt;br /&gt;
;DefaultValue: The DefaultValue is the value set when a new instance of a &amp;lt;tt&amp;gt;ControlTable&amp;lt;/tt&amp;gt; is created. Also, the &amp;lt;tt&amp;gt;PropertyGrid&amp;lt;/tt&amp;gt; shows properties with the default value in a normal font, and properties with a changed value in a bold font.&lt;br /&gt;
;Browsable: The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see [[#Hiding Properties Conditionally|Hiding Properties Conditionally]]&lt;br /&gt;
&lt;br /&gt;
In addition to this, a number of additional attributes and type converters are available in the &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; namespace:&lt;br /&gt;
&lt;br /&gt;
;ObjectDefaultValues:Allows default values to be set on other types than simple types&lt;br /&gt;
;PercentTypeConverter:Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)&lt;br /&gt;
&lt;br /&gt;
=== Hiding Properties Conditionally ===&lt;br /&gt;
=== Using Custom Classes inside a Control Table ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cloning Control Tables ===&lt;br /&gt;
=== Extending Control Tables ===&lt;br /&gt;
&lt;br /&gt;
=== Serialization and Deserialization of Control Tables ===&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4567</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4567"/>
		<updated>2010-05-21T06:52:42Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Error Handling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used.&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4566</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4566"/>
		<updated>2010-05-21T06:51:09Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;[[Design of Control Tables|ControlTables]]&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4565</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4565"/>
		<updated>2010-05-20T16:21:42Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The Regional Framework performs the following steps:&lt;br /&gt;
&lt;br /&gt;
# [[#Years to start period|Years to start period]] are calculated&lt;br /&gt;
# All treatment units are loaded and [[#Initialization of treatment units|initialized]]&lt;br /&gt;
# Treatment units are set aside for [[#Handling of nature conservation|nature conservation]]&lt;br /&gt;
# Total area of all treatment units is calculated&lt;br /&gt;
# Treatment units are allocated to forest domains and then to control categories&lt;br /&gt;
# [[#Initialization of treatment units|Treatment units are initialized]] again&lt;br /&gt;
# For each period:&lt;br /&gt;
## For each control category:&lt;br /&gt;
### Growth to next period is performed&lt;br /&gt;
### Restrictions are updated&lt;br /&gt;
### Treatments are executed&lt;br /&gt;
## Treatment units are allocated to new forest domains&lt;br /&gt;
# Results are saved&lt;br /&gt;
&lt;br /&gt;
== Years to start period ==&lt;br /&gt;
 &lt;br /&gt;
Number of years to start period is determined by the reference year and the start year given by the user. Start year cannot occur before reference year. If start year and reference year are the same, simulation will be started directly, and the results and settings for the first period will be for the reference year period. If reference year occurs after start year, two extra periods will be added to the simulation, and settings for period 1 and 2 will be used for those periods, while setting for period 3 will be for the reference year period. Similarly two extra periods will be added to the results.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Reference Year||Start Year||Period 0||Period 1||Period 2||Period 3&lt;br /&gt;
|-&lt;br /&gt;
|2006||2010||2006||2008||2010||2015&lt;br /&gt;
|-&lt;br /&gt;
|2010||2010||2010||2015||2020||2030&lt;br /&gt;
|}&lt;br /&gt;
== Initialization of treatment units ==&lt;br /&gt;
&lt;br /&gt;
Initialization of treatment units is done twice. The first time the treatment unit is initialized with age, volume, growth, and height for all trees using the settings of the default control category, as these values might be required when assigning treatment units to forest domains.&lt;br /&gt;
&lt;br /&gt;
The second time each treatment unit is assigned to a forest domain. Age, volume, growth, and height is assigned again (since another control category might be used this time), and growth to the start period is performed. Empty treatment units are also regenerated in this step.&lt;br /&gt;
&lt;br /&gt;
== Handling of nature conservation ==&lt;br /&gt;
&lt;br /&gt;
Treatment units are set aside for nature conservation at start of the simulation. Treatment units that has been set aside are included in the normal forest domain handling and treatment handling, but they are never prioritized for treatments.&lt;br /&gt;
&lt;br /&gt;
== Execution of treatments ==&lt;br /&gt;
&lt;br /&gt;
Execution of treatments follow a simple pattern:&lt;br /&gt;
&lt;br /&gt;
* Execution of treatments is done for a domain at a time&lt;br /&gt;
* There is a treatment planner for each type of treatment that can be performed&lt;br /&gt;
* Each treatment planner evaluates all treatment units in the domain, checks if each treatment unit can be treated by the treatment and sets a priority for it&lt;br /&gt;
* Each treatment planner executes treatments for the priorized treatment units until the desired goal for the treatment as set in the domain has been reached&lt;br /&gt;
&lt;br /&gt;
Treatments are executed in the following order:&lt;br /&gt;
&lt;br /&gt;
# Cleaning&lt;br /&gt;
# Final felling&lt;br /&gt;
# Fertilization&lt;br /&gt;
# Regeneration&lt;br /&gt;
# Thinning&lt;br /&gt;
# Intensive fertilization&lt;br /&gt;
&lt;br /&gt;
Several treatments in the same period is not allowed. This means if several treatments are possible for a treatment unit, the treatment with the highest priority is most likely to be performed.&lt;br /&gt;
&lt;br /&gt;
== Forest Domains ==&lt;br /&gt;
&lt;br /&gt;
=== How it should work ===&lt;br /&gt;
A &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; is a classification of treatment units. Each forest domain has two properties that are of interest for the regional framework:&lt;br /&gt;
&lt;br /&gt;
;ChangeForestDomainAllowed:Can treatment units assigned to the domain be moved to other domains&lt;br /&gt;
;ChangeMaturityClass:At which maturity class can the change be done&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; specifies how treatments are applied, e.g. a kind of management system. Each control category has the following property of interest here:&lt;br /&gt;
&lt;br /&gt;
;TargetArea: Percentage of the total area being analyzed that should be allocated to the control category&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; is connected to one or more &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt;. The same &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; may be connected to more than one domain. &lt;br /&gt;
&lt;br /&gt;
In the regional framework, it is evaluated for each period which treatment units belongs to which control category.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
Say that there are three control categories:&lt;br /&gt;
&lt;br /&gt;
* Intensive management (10%)&lt;br /&gt;
* Continous management (20%)&lt;br /&gt;
* Even Aged Management (100%)&lt;br /&gt;
&lt;br /&gt;
And three forest domains, assigned to categories:&lt;br /&gt;
&lt;br /&gt;
;Oak Forest: Continous Management , Even Aged Management&lt;br /&gt;
;Spruce Forest: Intensive Management, Even Aged Management&lt;br /&gt;
;Other Forest: Intensive Management, Continous Management, Even Aged Management&lt;br /&gt;
&lt;br /&gt;
The regional framework will do as follows:&lt;br /&gt;
&lt;br /&gt;
# If possible, allocated oak forest to continous management&lt;br /&gt;
# If the area of the oak forest is more than 10%, use even aged management for oak forest&lt;br /&gt;
# Similarly try to assign spruce forest to intensive management&lt;br /&gt;
# For other forest, use intensive management if possible (there was not enough spruce forest), if not try with continous management, if that not works even aged management will have to do&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
&lt;br /&gt;
# Total area of the analysis area is calculated&lt;br /&gt;
# For each period:&lt;br /&gt;
## If first period:&lt;br /&gt;
### All treatment units are added to a list of not assigned treatment units&lt;br /&gt;
## If not first period:&lt;br /&gt;
### Treatment units that are in a forest domain where change of forest domain is allowed, and has the maturity class of the forest domain, are added to a list of not assigned treatment units&lt;br /&gt;
## Remove all treatment units set aside from nature conservation from the list of not assigned treatment units, assign these to the default control category of their forest domain&lt;br /&gt;
## For each forest domain:&lt;br /&gt;
### For each control category in the domain:&lt;br /&gt;
#### While the assigned area of the control category is less than the target area of the control category, and there are available treatment units:&lt;br /&gt;
##### Pick a treatment unit with matching forest domain from the list of not assigned treatment units&lt;br /&gt;
##### Add the treatment unit to the control category&lt;br /&gt;
##### Increase the assigned area of the control category&lt;br /&gt;
## For each treatment units that not yet has been assigned:&lt;br /&gt;
### Add it to the default control category of its forest domain&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4564</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4564"/>
		<updated>2010-05-20T16:20:10Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The Regional Framework performs the following steps:&lt;br /&gt;
&lt;br /&gt;
# [[#Years to start period|Years to start period]] are calculated&lt;br /&gt;
# All treatment units are loaded and [[#Initialization of treatment units|initialized]]&lt;br /&gt;
# Treatment units are set aside for [[#Handling of nature conservation|nature conservation]]&lt;br /&gt;
# Total area of all treatment units is calculated&lt;br /&gt;
# Treatment units are allocated to forest domains and then to control categories&lt;br /&gt;
# [[#Initialization of treatment units|Treatment units are initialized]] again&lt;br /&gt;
# For each period:&lt;br /&gt;
## For each control category:&lt;br /&gt;
### Growth to next period is performed&lt;br /&gt;
### Restrictions are updated&lt;br /&gt;
### Treatments are executed&lt;br /&gt;
## Treatment units are allocated to new forest domains&lt;br /&gt;
# Results are saved&lt;br /&gt;
&lt;br /&gt;
== Years to start period ==&lt;br /&gt;
 &lt;br /&gt;
Number of years to start period is determined by the reference year and the start year given by the user. Start year cannot occur before reference year. If start year and reference year are the same, simulation will be started directly, and the results and settings for the first period will be for the reference year period. If reference year occurs after start year, two extra periods will be added to the simulation, and settings for period 1 and 2 will be used for those periods, while setting for period 3 will be for the reference year period. Similarly two extra periods will be added to the results.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Reference Year||Start Year||Period 0||Period 1||Period 2||Period 3&lt;br /&gt;
|-&lt;br /&gt;
|2006||2010||2006||2008||2010||2015&lt;br /&gt;
|-&lt;br /&gt;
|2010||2010||2010||2015||2020||2030&lt;br /&gt;
|}&lt;br /&gt;
== Initialization of treatment units ==&lt;br /&gt;
&lt;br /&gt;
Initialization of treatment units is done twice. The first time the treatment unit is initialized with age, volume, growth, and height for all trees using the settings of the default control category, as these values might be required when assigning treatment units to forest domains.&lt;br /&gt;
&lt;br /&gt;
The second time each treatment unit is assigned to a forest domain. Age, volume, growth, and height is assigned again (since another control category might be used this time), and growth to the start period is performed. Empty treatment units are also regenerated in this step.&lt;br /&gt;
&lt;br /&gt;
== Handling of nature conservation ==&lt;br /&gt;
&lt;br /&gt;
Treatment units are set aside for nature conservation at start of the simulation. Treatment units that has been set aside are included in the normal forest domain handling and treatment handling, but they are never prioritized for treatments.&lt;br /&gt;
&lt;br /&gt;
== Execution of treatments ==&lt;br /&gt;
&lt;br /&gt;
Execution of treatments follow a simple pattern:&lt;br /&gt;
&lt;br /&gt;
* Execution of treatments is done for a domain at a time&lt;br /&gt;
* There is a treatment planner for each type of treatment that can be performed&lt;br /&gt;
* Each treatment planner evaluates all treatment units in the domain, checks if each treatment unit can be treated by the treatment and sets a priority for it&lt;br /&gt;
* Each treatment planner executes treatments for the priorized treatment units until the desired goal for the treatment as set in the domain has been reached&lt;br /&gt;
&lt;br /&gt;
Treatments are executed in the following order:&lt;br /&gt;
&lt;br /&gt;
# Cleaning&lt;br /&gt;
# Final felling&lt;br /&gt;
# Fertilization&lt;br /&gt;
# Regeneration&lt;br /&gt;
# Thinning&lt;br /&gt;
# Intensive fertilization&lt;br /&gt;
&lt;br /&gt;
Several treatments in the same period is not allowed. This means if several treatments are possible for a treatment unit, the treatment with the highest priority is most likely to be performed.&lt;br /&gt;
&lt;br /&gt;
== Forest Domains ==&lt;br /&gt;
&lt;br /&gt;
=== How it should work ===&lt;br /&gt;
A &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; is a classification of treatment units. Each forest domain has two properties that are of interest for the regional framework:&lt;br /&gt;
&lt;br /&gt;
;ChangeForestDomainAllowed:Can treatment units assigned to the domain be moved to other domains&lt;br /&gt;
;ChangeMaturityClass:At which maturity class can the change be done&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; specifies how treatments are applied, e.g. a kind of management system. Each control category has the following property of interest here:&lt;br /&gt;
&lt;br /&gt;
;TargetArea: Percentage of the total area being analyzed that should be allocated to the control category&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; is connected to one or more &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt;. The same &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; may be connected to more than one domain. &lt;br /&gt;
&lt;br /&gt;
In the regional framework, it is evaluated for each period which treatment units belongs to which control category.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
Say that there are three control categories:&lt;br /&gt;
&lt;br /&gt;
* Intensive management (10%)&lt;br /&gt;
* Continous management (20%)&lt;br /&gt;
* Even Aged Management (100%)&lt;br /&gt;
&lt;br /&gt;
And three forest domains, assigned to categories:&lt;br /&gt;
&lt;br /&gt;
;Oak Forest: Continous Management , Even Aged Management&lt;br /&gt;
;Spruce Forest: Intensive Management, Even Aged Management&lt;br /&gt;
;Other Forest: Intensive Management, Continous Management, Even Aged Management&lt;br /&gt;
&lt;br /&gt;
The regional framework will do as follows:&lt;br /&gt;
&lt;br /&gt;
# If possible, allocated oak forest to continous management&lt;br /&gt;
# If the area of the oak forest is more than 10%, use even aged management for oak forest&lt;br /&gt;
# Similarly try to assign spruce forest to intensive management&lt;br /&gt;
# For other forest, use intensive management if possible (there was not enough spruce forest), if not try with continous management, if that not works even aged management will have to do&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
&lt;br /&gt;
# Total area of the analysis area is calculated&lt;br /&gt;
# For each period:&lt;br /&gt;
## If first period:&lt;br /&gt;
### All treatment units are added to a list of not assigned treatment units&lt;br /&gt;
## If not first period:&lt;br /&gt;
### Treatment units that are in a forest domain where change of forest domain is allowed, and has the maturity class of the forest domain,&lt;br /&gt;
## Remove all treatment units set aside from nature conservation from the list of not assigned treatment units&lt;br /&gt;
## For each forest domain:&lt;br /&gt;
### For each control category in the domain:&lt;br /&gt;
#### While the assigned area of the control category is less than the target area of the control category, and there are available treatment units:&lt;br /&gt;
##### Pick a treatment unit with matching forest domain from the list of not assigned treatment units&lt;br /&gt;
##### Add the treatment unit to the control category&lt;br /&gt;
##### Increase the assigned area of the control category&lt;br /&gt;
## For each treatment units that not yet has been assigned:&lt;br /&gt;
### Add it to the default control category of its forest domain&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4563</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4563"/>
		<updated>2010-05-20T16:07:14Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Forest Domains */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4562</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4562"/>
		<updated>2010-05-20T14:31:47Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4561</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4561"/>
		<updated>2010-05-20T14:31:08Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Forest Domains */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4560</id>
		<title>Regional Framework Design</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=Regional_Framework_Design&amp;diff=4560"/>
		<updated>2010-05-20T14:18:20Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The Regional Framework performs the following steps:&lt;br /&gt;
&lt;br /&gt;
# [[#Years to start period|Years to start period]] are calculated&lt;br /&gt;
# All treatment units are loaded and [[#Initialization of treatment units|initialized]]&lt;br /&gt;
# Treatment units are set aside for [[#Handling of nature conservation|nature conservation]]&lt;br /&gt;
# Total area of all treatment units is calculated&lt;br /&gt;
# Treatment units are allocated to forest domains&lt;br /&gt;
# [[#Initialization of treatment units|Treatment units are initialized]] again&lt;br /&gt;
# For each period:&lt;br /&gt;
## For each domain:&lt;br /&gt;
### Growth to next period is performed&lt;br /&gt;
### Restrictions are updated&lt;br /&gt;
### Treatments are executed&lt;br /&gt;
## Treatment units are allocated to new forest domains&lt;br /&gt;
# Results are saved&lt;br /&gt;
&lt;br /&gt;
== Years to start period ==&lt;br /&gt;
 &lt;br /&gt;
Number of years to start period is determined by the reference year and the start year given by the user. Start year cannot occur before reference year. If start year and reference year are the same, simulation will be started directly, and the results and settings for the first period will be for the reference year period. If reference year occurs after start year, two extra periods will be added to the simulation, and settings for period 1 and 2 will be used for those periods, while setting for period 3 will be for the reference year period. Similarly two extra periods will be added to the results.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Reference Year||Start Year||Period 0||Period 1||Period 2||Period 3&lt;br /&gt;
|-&lt;br /&gt;
|2006||2010||2006||2008||2010||2015&lt;br /&gt;
|-&lt;br /&gt;
|2010||2010||2010||2015||2020||2030&lt;br /&gt;
|}&lt;br /&gt;
== Initialization of treatment units ==&lt;br /&gt;
&lt;br /&gt;
Initialization of treatment units is done twice. The first time the treatment unit is initialized with age, volume, growth, and height for all trees using the settings of the default control category, as these values might be required when assigning treatment units to forest domains.&lt;br /&gt;
&lt;br /&gt;
The second time each treatment unit is assigned to a forest domain. Age, volume, growth, and height is assigned again (since another control category might be used this time), and growth to the start period is performed. Empty treatment units are also regenerated in this step.&lt;br /&gt;
&lt;br /&gt;
== Handling of nature conservation ==&lt;br /&gt;
&lt;br /&gt;
Treatment units are set aside for nature conservation at start of the simulation. Treatment units that has been set aside are included in the normal forest domain handling and treatment handling, but they are never prioritized for treatments.&lt;br /&gt;
&lt;br /&gt;
== Execution of treatments ==&lt;br /&gt;
&lt;br /&gt;
Execution of treatments follow a simple pattern:&lt;br /&gt;
&lt;br /&gt;
* Execution of treatments is done for a domain at a time&lt;br /&gt;
* There is a treatment planner for each type of treatment that can be performed&lt;br /&gt;
* Each treatment planner evaluates all treatment units in the domain, checks if each treatment unit can be treated by the treatment and sets a priority for it&lt;br /&gt;
* Each treatment planner executes treatments for the priorized treatment units until the desired goal for the treatment as set in the domain has been reached&lt;br /&gt;
&lt;br /&gt;
Treatments are executed in the following order:&lt;br /&gt;
&lt;br /&gt;
# Cleaning&lt;br /&gt;
# Final felling&lt;br /&gt;
# Fertilization&lt;br /&gt;
# Regeneration&lt;br /&gt;
# Thinning&lt;br /&gt;
# Intensive fertilization&lt;br /&gt;
&lt;br /&gt;
Several treatments in the same period is not allowed. This means if several treatments are possible for a treatment unit, the treatment with the highest priority is most likely to be performed.&lt;br /&gt;
&lt;br /&gt;
== Forest Domains ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4559</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4559"/>
		<updated>2010-05-20T12:51:12Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Forest model and Calculations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator Design|Treatment Program Generator]], the [[Tactical Treatment Program Generator Design|Tactical Treatment Program Generator]], and the [[Regional Framework Design|Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4558</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4558"/>
		<updated>2010-05-20T12:49:32Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Forest model and Calculations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models. Currently, three simulation models are implemented in Heureka: the (strategic) [[Treatment Program Generator]], the [[Tactical Treatment Program Generator]], and the [[Regional Framework]].&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4557</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4557"/>
		<updated>2010-05-20T12:43:29Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4556</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4556"/>
		<updated>2010-05-20T12:43:13Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer/&amp;lt;/tt&amp;gt; component.&lt;br /&gt;
&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4555</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4555"/>
		<updated>2010-05-20T12:42:49Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Kommandon */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The three layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
 &lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
=== MVC ===&lt;br /&gt;
&lt;br /&gt;
Linking between user interface and the domain model is done with the architectural pattern Model-View-Controller (Reenskaug 1979).&lt;br /&gt;
 &lt;br /&gt;
The model is a domain entity. When the entity is changed, it signals that with an event so that all views rendering the entity can update themselves. The event &amp;lt;tt&amp;gt;PropertyChanged&amp;lt;/tt&amp;gt; is used when a property is changed, the interface &amp;lt;tt&amp;gt;IBindingList&amp;lt;/tt&amp;gt; is used when a list or collection is changed. In some cases other events are also used, in &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.ComponentModel&amp;lt;/tt&amp;gt; there are a few more EventArgs that can be used. That namespace also contains the class &amp;lt;tt&amp;gt;ExtendedBindingList&amp;lt;/tt&amp;gt; which is recommended for collections that can be bound.&lt;br /&gt;
&lt;br /&gt;
The view is any kind of graphical control, such as a TextBox, a DataGrid, a TreeView, or a Map. The view can show and change some parts of the entity.&lt;br /&gt;
&lt;br /&gt;
The controller is the object that reacts on user inputs, typically event handlers in a form.&lt;br /&gt;
&lt;br /&gt;
When developing with MVC it is important not to short-circuit the view and the controller when they are implemented in the same class. The event handler should only update the model, and not trigger changes in the view directly. &lt;br /&gt;
&lt;br /&gt;
=== Dependency inversion ===&lt;br /&gt;
&lt;br /&gt;
To reduce dependencies between classes and subsystems, should the subsystems that need a particular service define an interface for that service. For example, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem needs biomass to be calculated. To avoid a direct (and circular) dependency from &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;Forest&amp;lt;/tt&amp;gt; subsystem declares an interface, &amp;lt;tt&amp;gt;IBiomassService&amp;lt;/tt&amp;gt;, and the &amp;lt;tt&amp;gt;Biomass&amp;lt;/tt&amp;gt; subsystem implements that interface.&lt;br /&gt;
&lt;br /&gt;
With dependency inversation, a new problem arises, how does an object locate the needed services? There are two common approaches to solving this problem: either Dependency Injection is used, or a Service Locator is used. For Heureka, the latter approach has been used.&lt;br /&gt;
&lt;br /&gt;
The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.Services&amp;lt;/tt&amp;gt; implements a service locator. Key classes in interfaces in that subsystem are:&lt;br /&gt;
&lt;br /&gt;
;IService:Interface that must be implemented by all services&lt;br /&gt;
;Service&amp;lt;T&amp;gt;:Generic class for accessing a service&lt;br /&gt;
;ServiceAttribute:Attribute that should be set on all services that should be auto loaded&lt;br /&gt;
;ServiceBase:Base class for implementing a service&lt;br /&gt;
;ServiceManager:The service locator&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; is a Singleton. It supports auto loading of services (all services marked with the service attribute will be loaded at application startup) as well as explicit loading of services (very useful in unit tests).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Services&amp;lt;/tt&amp;gt; subsystem was introduced relatively late in the project but has proven to be very flexible and useful. In future development, it is recommended to use it more frequently to reduce dependencies in the system. The recommended approach is that when:&lt;br /&gt;
&lt;br /&gt;
* A class needs to instantiate other classes (except .Net classes), a FactoryService should be implemented&lt;br /&gt;
* A class needs to use another subsystem, an interface to that subsystem should be implemented&lt;br /&gt;
&lt;br /&gt;
Static classes and singletons should never be used, with the &amp;lt;tt&amp;gt;ServiceManager&amp;lt;/tt&amp;gt; as the single exception to this rule.&lt;br /&gt;
&lt;br /&gt;
=== Persisting Data ===&lt;br /&gt;
&lt;br /&gt;
The system uses both the file system and RDBMS:s (SQL Server) to store data.&lt;br /&gt;
&lt;br /&gt;
* Forest data (stand registers, inventory data, GIS data, treatment units etc) are stored in a RDBMS, the &amp;quot;ForestDb&amp;quot;&lt;br /&gt;
* Calculated results and optimization results (plans) are stored in another RDBMS, the &amp;quot;ResultDb&amp;quot;&lt;br /&gt;
* Project information and templates are stored in the file system (typically in the user's document folder)&lt;br /&gt;
* Application configuration is stored in the file system (typically in the user's application data folder)&lt;br /&gt;
&lt;br /&gt;
Storgate to files are mainly done via serialization. However, a major drawback with serialization is that versioning can be a problem. Also, performance can be an issue. The subsystem &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.SerializationManagement&amp;lt;/tt&amp;gt; provides helper classes to resolve some of these issues. The classes &amp;lt;tt&amp;gt;SerializationReader&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SerializationWriter&amp;lt;/tt&amp;gt; improves performance drastically. A recommended practice is to always serialize a version number first. By doing this, deserialization of different versions can easily be implemented. A different problem is when a class changes its name or becomes obsolete. A solution for that problem has not been implemented in the Heureka system, but it should be possible to do it using the &amp;lt;tt&amp;gt;[[http://msdn.microsoft.com/en-US/library/system.runtime.serialization.serializationbinder|SerializationBinder]]&amp;lt;/tt&amp;gt; class in the .Net framework.&lt;br /&gt;
&lt;br /&gt;
For simple configuration data, the class &amp;lt;tt&amp;gt;ConfigurationStore&amp;lt;/tt&amp;gt; should be used. &lt;br /&gt;
&lt;br /&gt;
For control tables, a helper class that serializes control tables has been developed. Thus it is not necessary to implement serialization for control tables.&lt;br /&gt;
&lt;br /&gt;
For interaction with RDBMS the following techniques are used:&lt;br /&gt;
;Data readers: For fast loading of objects, mainly used for forest data&lt;br /&gt;
;Typed data sets: Used when the user is updating data&lt;br /&gt;
;Custom OR-mappning: Used for the result database&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
&lt;br /&gt;
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as &amp;lt;tt&amp;gt;ArgumentException&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ArgumentNullException&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;InvalidOperationException&amp;lt;/tt&amp;gt;. In other cases Heureka specific exceptions, inheriting from &amp;lt;tt&amp;gt;ApplicationException&amp;lt;/tt&amp;gt;, are used&lt;br /&gt;
&lt;br /&gt;
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use&lt;br /&gt;
 &amp;lt;tt&amp;gt;int.TryParse()&amp;lt;/tt&amp;gt; than &amp;lt;tt&amp;gt;int.Parse()&amp;lt;/tt&amp;gt; as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.&lt;br /&gt;
&lt;br /&gt;
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.&lt;br /&gt;
&lt;br /&gt;
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use &amp;lt;tt&amp;gt;Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog&amp;lt;/tt&amp;gt; to show error messages.&lt;br /&gt;
&lt;br /&gt;
The exception message should be brief. If a longer description is needed, set the &amp;lt;tt&amp;gt;HelpLink&amp;lt;/tt&amp;gt; for the exception.&lt;br /&gt;
&lt;br /&gt;
=== Kommandon ===&lt;br /&gt;
&lt;br /&gt;
The Command design pattern is used to encapsulate actions that the user performs into separate objects. There are several benefits with this simple pattern, so it should be used frequently:&lt;br /&gt;
&lt;br /&gt;
* Command makes it possible to implement Undo and Redo&lt;br /&gt;
* Command moves logic from forms into separate classes, and thus reduces the complexity of forms&lt;br /&gt;
* The logic in a Command can easily be used in separate forms and applications&lt;br /&gt;
&lt;br /&gt;
Technically, commands belongs to the presentation services. Commands are allowed to launch dialogs and message boxes, guiding the user through a flow.&lt;br /&gt;
&lt;br /&gt;
=== Reports ===&lt;br /&gt;
&lt;br /&gt;
Standrd reports are developed in Visual Studio as Microsoft Client Report Definitions (rdlc). These are shown in the applications with the &amp;lt;tt&amp;gt;ReportViewer/&amp;lt;tt&amp;gt; component.&lt;br /&gt;
=== Help ===&lt;br /&gt;
&lt;br /&gt;
The applications should have support for online help.&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4554</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4554"/>
		<updated>2010-05-20T12:39:12Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Error Handling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4553</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4553"/>
		<updated>2010-05-20T12:31:28Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Help = */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4552</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4552"/>
		<updated>2010-05-20T12:31:06Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Persisting Data = */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4551</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4551"/>
		<updated>2010-05-20T09:35:48Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Dependency inversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4550</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4550"/>
		<updated>2010-05-20T09:19:05Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Design Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4549</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4549"/>
		<updated>2010-05-20T07:11:31Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Layering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The tree layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
&lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4548</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4548"/>
		<updated>2010-05-20T07:10:55Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* Design Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
=== Layering ===&lt;br /&gt;
&lt;br /&gt;
[[file:layering.png]]&lt;br /&gt;
&lt;br /&gt;
The system is built with a layered architecture (see for example [[ISBN 0321154959]|Bass et al: Software Architecture in Practice]]. The layering is based on the system logic, where each layer adds functionality from a lower layer.&lt;br /&gt;
&lt;br /&gt;
The tree layers are:&lt;br /&gt;
&lt;br /&gt;
;Application Layer: Each application is a separate subsystem. An application connects the domain specific subsystems into the functionality provided by the application.&lt;br /&gt;
;Domain Layer: A large number of subsystems with different types of domain specific functionality. Each subsystem has its own logic, and in many cases also presentation and persistence services. By having the presentation in the domain layer, UI functionality can be reused between applications.&lt;br /&gt;
;Base Layer: General purpose support functions.&lt;br /&gt;
&lt;br /&gt;
The purpose of the layering is to achieve modifiability by isolation of changes. Changes in a higher layer does not affect a lower layer at all.&lt;br /&gt;
&lt;br /&gt;
The layering is not strict, meaning that a higher layer can access any lower layer.&lt;br /&gt;
&lt;br /&gt;
A similar layering is proposed in IBM Rational Unified Process, and in Domain Driven Design. The advantage of layering by generality as opposed to layering by type (as proposed by Microsoft) is lower coupling and higher cohesion. &lt;br /&gt;
&lt;br /&gt;
Inside a subsystem, layering by type, i.e. UI -&amp;gt; Logic -&amp;gt; DB should be done (if a subsystem has a presentation and/or persistence service). A subsystem should be able to use the logic of another subsystem without refering to the presentation or persistence service of that subsystem. The persistence service should be encapsulated inside the subsystem and not be used directly by other subsystems. The presentation service of a subsystem should be available for composition of UI.&lt;br /&gt;
&lt;br /&gt;
''Unfortunately the subsystem layering has not always been used, in many cases several subsystems access the same tables in the database directly. Some subsystems are also poorly layered, e.g. with database code inside the UI, or UI code inside the logic.''&lt;br /&gt;
&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=File:Layering.png&amp;diff=4547</id>
		<title>File:Layering.png</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=File:Layering.png&amp;diff=4547"/>
		<updated>2010-05-20T06:47:32Z</updated>

		<summary type="html">&lt;p&gt;Fkl: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
	<entry>
		<id>https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4546</id>
		<title>System Architecture</title>
		<link rel="alternate" type="text/html" href="https://www.heurekaslu.se/w/index.php?title=System_Architecture&amp;diff=4546"/>
		<updated>2010-05-19T14:32:15Z</updated>

		<summary type="html">&lt;p&gt;Fkl: /* = Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Architectural Goals and Quality ==&lt;br /&gt;
&lt;br /&gt;
For Heureka, the two most important quality goals are modifiability and performance. The system should be flexible enough to allow maintenance and further development in a cost effective manner. At the same time performance should be good enough to allow simulation on large amounts of data. To a certain extent, these goals are contradictable.&lt;br /&gt;
&lt;br /&gt;
In addition to this, testability is an important quality aspect. As many parts as possible should be possible to test automatically, e.g. with unit testing tools such as [http://www.nunit.org/ NUnit]. This sometimes means that sub functions must be made public so that they can be tested from external code. Over time, this goal has been proven more important than originally expected. This means that this goal has not always been met in the existing code, for instance many classes has a lot of dependencies on other classes making them harder to test.* &lt;br /&gt;
&lt;br /&gt;
Other quality goals are less important:&lt;br /&gt;
&lt;br /&gt;
* Security. There are no specific security requirements. The system will use security functions available in the database and operating system.&lt;br /&gt;
* Availability. The system is a single user application, so availability is not considered in the architecture.&lt;br /&gt;
* Portability. Portability is not required.&lt;br /&gt;
&lt;br /&gt;
== Logical View ==&lt;br /&gt;
&lt;br /&gt;
=== Forest model and Calculations ===&lt;br /&gt;
[[file:Forest_and_Calculations.png]]&lt;br /&gt;
&lt;br /&gt;
The key entity in Heureka is the Treatment Unit, that represents a stand, i.e. an area restricted in space, with the same type of forest. A Treatment Unit is the smallest unit treatments are applied for. Each treatment unit contains one or more predictions units. A prediction unit represents a plot or a cell inside the treatment unit. Each prediction unit contains trees. Trees have [[Handling of tree states|different states]], identifying if the tree object represents a sapling, a tree, is dead and so forth. Each of these entities [[handle different time periods]].&lt;br /&gt;
&lt;br /&gt;
Treatments are simulated in Heureka with different type of treatment models such as regeneration, fertilization, cleaning, thinning, and final felling.&lt;br /&gt;
&lt;br /&gt;
Growth and yield models calculates tree related values such as volume, basal area growth, height, age, and bark thickness. With help of the growth models, a treatment unit can grow, i.e. the state in a future time period can be calculated.&lt;br /&gt;
&lt;br /&gt;
[[Result models]] are used to calculate different types on results. Based on the state of a treatment unit in a given time period, different types of results can be calculated, such as cost and revenue of treatments, amount of biomass in the living forest, or amount of litter added to the ground. A result model may also produce a result based on the results in other result models (e.g. the recreation model uses input from the dead wood model).&lt;br /&gt;
&lt;br /&gt;
Simulation models or frameworks, allows treatment programs to be calculated for a treatment unit. A simulation model utilizes the growth and yield models, the treatment models, and sometimes also result models, to simulate different alternatives for managing a treatment unit. When growth prognosis and treatments has been simulated for a number of periods, the treatment unit (together with its prediction units and their trees and saplings) contains information about the forest state in all periods that were included in the simulation. The results can be saved in a treatment program, which contains results for all periods with the desired result models.&lt;br /&gt;
&lt;br /&gt;
An optimization model is used to create a plan. A plan consists of a selection of treatment programs (one for each treatment unit in the plan), that gives the best result according to the optimization model. An optimization model is defined using the results from the result models. Any variable produced by a result model can be used in an optimization model. Optimization models differs from other models in Heureka, these are the only models that are defined by the user (all other models are programmed into the system).&lt;br /&gt;
&lt;br /&gt;
Treatment units may be classified in forest domains. A user may define a forest domain, based on variables from the result models. The forest domain is then used to configure a simulation model.&lt;br /&gt;
&lt;br /&gt;
=== Data Import ===&lt;br /&gt;
&lt;br /&gt;
[[file:Data_Import.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; can be created from a NFI plot. In this case, a&amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each NFI plot (if the NFI plot is splitted a &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt; and a &amp;lt;tt&amp;gt;PredictionUnit&amp;lt;/tt&amp;gt; is created for each part of the plot).&lt;br /&gt;
&lt;br /&gt;
Similarly FMPP data can be imported into Heureka (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
Another option is to import a stand register. From &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s in the stand register, &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s can be simulated. In this case, trees or saplings are created for the &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;, based on stand level variables in the &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;. The simulation process is stochastic, meaning that the result will be slightly different each time if repeated several times for the same &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is also possible to get data to Heureka by making a sample design, choosing &amp;lt;tt&amp;gt;StandObject&amp;lt;/tt&amp;gt;s to be inventoried, and then to make a field inventory using [[Ivent]], to get real plot data and inventoried trees and from that data create &amp;lt;tt&amp;gt;TreatmentUnit&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
The last option to get data into Heureka is to manually enter data using [[StandWise]] (not shown in figure).&lt;br /&gt;
&lt;br /&gt;
All forest data is stored in a relational database.&lt;br /&gt;
&lt;br /&gt;
=== Projects ===&lt;br /&gt;
&lt;br /&gt;
[[file:Projects.png]]&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;ControlCategories&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ForestDomains&amp;lt;/tt&amp;gt;. Each &amp;lt;tt&amp;gt;ForestDomain&amp;lt;/tt&amp;gt; refers to a &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt;, and each &amp;lt;tt&amp;gt;ControlCategory&amp;lt;/tt&amp;gt; contains a number of &amp;lt;tt&amp;gt;ControlTables&amp;lt;/tt&amp;gt;, each of which contains user settings for a model or a group of related models in the system.&lt;br /&gt;
&lt;br /&gt;
Also, a &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; contains the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; that the user is working with (the &amp;lt;tt&amp;gt;TreatmentUnits&amp;lt;/tt&amp;gt; are actually kept in an &amp;lt;tt&amp;gt;AnalysisArea&amp;lt;/tt&amp;gt;, not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;Project&amp;lt;/tt&amp;gt; may also contain other items, such as optimization models (not shown in the figure).&lt;br /&gt;
&lt;br /&gt;
The project information is saved as files in the file system.&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
== Technical Environment ==&lt;/div&gt;</summary>
		<author><name>Fkl</name></author>
	</entry>
</feed>