Difference between revisions of "Treatment Program Generator Design"

From Heureka Wiki
Jump to navigation Jump to search
(Created page with '== Creating Treatment Programs for an analysis area == Klassen TreatmentProgramManager håller ihop generering av skötselprogram för ett analysområde. Algoritmen för att gö�?�')
 
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
[[Category:System design]]
 
== Creating Treatment Programs for an analysis area ==
 
== Creating Treatment Programs for an analysis area ==
  
Klassen TreatmentProgramManager håller ihop generering av skötselprogram för ett analysområde.
+
The class <tt>TreatmentProgramManager</tt> manages treatment program generation for an analysis area, as follows:
Algoritmen för att göra detta är som följer:
+
 
1. Utvärdera skogsdomäner och tilldela åtgärdsenheter till varje domän.
+
# <tt>ForestDomains</tt> are evaluated and each treatment unit is assigned to a domain.
2. För varje domän:
+
# For each domain:
2.1. Fördela v för naturvårdshänsyn
+
## Treatment units are set aside for nature conservation
2.2. Skapa vanliga skötselprogram för åtgärdsenheter som inte är avsatta
+
## For treatment units that not has been set aside, the <tt>TreatmentProgramGenerator</tt> is called and treatment programs of the desired types (unmanaged, continuous management, or even aged management, given by the user) are generated
2.3. Skapa skötselprogram med fri utveckling för avsatta åtgärdsenheter.
+
## For treatment units that has been set aside, unmanaged treatment programs are generated by the <tt>TreatmentProgramGenerator</tt>.
Skötselprogramgenereringen är både prestanda- och minneskrävande. För att få bra prestanda vid läsning från databas läser man i steg 2.2 och 2.3 ovan upp 20 åtgärdsenheter åt gången (eller så många som är kvar om det är färre än 20). För att minska minnesutnyttjandet släpper man minnet för en åtgärdsenhet när alla skötselprogram för den är klara.
+
 
 +
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).
  
 
== Creating Continous Management and Unmanaged Treatment Programs ==
 
== Creating Continous Management and Unmanaged Treatment Programs ==
  
Genering av skötselprogram för blädning och fri utveckling är trivialt. Man skriver helt enkelt fram åtgärdsenheten önskat antal perioder. För blädning utvärderar man i varje period om blädning är tillåtet och utför i så fall en blädning.
+
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.  
 +
 
 +
For continous management, it is evaluated in each period if selection felling is allowed or not. If allowed, selection felling is performed.
  
 
== Creating Even Aged Treatment Programs ==
 
== Creating Even Aged Treatment Programs ==
  
Generera skötselprogram för trakthyggesbruk är mer komplext. Nedanstående diagram visar principen för detta:
+
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).
+
 
Initiering sker en gång per åtgärdsenhet. Behövs föryngring sker det och åtgärdsenheten skrivs i så fall fram så långt att föryngringen aktiverats på alla provytor.
+
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.
Skötselspecifikationer skapas först för den första generationen en gång, sedan kan detta upprepas flera gånger för kommande generationer och alternativ.
+
 
Ett alternativ skapas för varje skötselspecifikation. . Därefter tillämpas även eventuell gödslingspolicy.
+
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.
Sedan fortsätter man att skapa fler generationer till dess planeringshorisonten är nådd och det finns minst en komplett generation. Diagrammet ovan visar hur nya generationer simuleras, det finns även andra varianter för att skapa nya generationer, mer om det nedan.
+
 
 +
The diagram below illustrates the process for treatment program generation:
 +
 
 +
[[file:tpg.png]]
 +
 
 +
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).
 +
 
 +
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).
 +
 
 +
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.
 +
 
 
=== Creating Treatment Specifications ===
 
=== Creating Treatment Specifications ===
  
En skötselspecifikation innehåller en beskrivning av när röjning, första gallring och slutavverkning ska ske (röjning och första gallring kan vara utelämnade, slutavverkning finns alltid med). Målet med att skapa skötselspecifikationer är att ta fram de kombinationer som är möjliga, utifrån användarens inställningar och skogens tillstånd.
+
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).
Först bestämmer man vilka åtgärder som är möjliga. , för röjning och gallring innebär det att man skriver fram åtgärdsenheten och provar när röjning och gallring är möjligt. Utifrån användarens inställningar har man nu fått fram 1-3 åtgärder med ett område för varje åtgärd i varsin TreatmentSpecificationRange.
+
 
Det kan se ut så här:
+
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.
period 4-5
+
 
period 8-10
+
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 <tt>TreatmentSpecificationRange</tt>. It may look like this:
period 10-14
+
 
Därefter sorteras åtgärderna i omvänd prioritetsordning, så att den åtgärd som har högst prioritet (ska varieras mest) ligger sist. :
+
# Cleaning period 4-5
period 4-5
+
# Thinning period 8-10
period 10-14
+
# Final Felling period 10-14
period 8-10
+
 
Sista steget är att utifrån framräknade områden ta fram en lista över specifikationer som är möjliga. Det sker i två delsteg, först skapas alla permutationer som är möjliga (med hjälp av klassen TreatmentSpecificationEnumerator), därefter filtreras de permutationer som inte är tillåtna bort (av klassen TreatmentSpecificationCollection). Det kan se ut så här:
+
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:
Röjning Slutavverkning Gallring Kommentar
+
 
4 10 8
+
# Cleaning period 4-5
4 10 9
+
# Final Felling period 10-14
4 10 10 Filtreras bort eftersom gallring och slutavverkning inte kan ske samtidigt
+
# Thinning period 8-10
4 11 8
+
 
4 11 9
+
The last step is to, from the ranges, create a list of possible specifications. The class <tt>TreatmentSpecificationEnumerator</tt> creates an enumeration of all possible treatment specifications from the ranges and the class <tt>TreatmentSpecificationCollection</tt> filters the invalid permutations.
4 11 10
+
 
5 10 8
+
It might look like this:
osv
+
 
 +
{| border = "1"
 +
|-
 +
|Cleaning||Final Felling||Thinning||Comment
 +
|-
 +
|4||10||8||
 +
|-
 +
|4||10||9||
 +
|-
 +
|4||10||10||Filtered since cleaning and final felling not can occur in the same period
 +
|-
 +
|4||11||8||
 +
|-
 +
|4||11||9||
 +
|-
 +
|4||11||10||
 +
|-
 +
|5||10||8||
 +
|-
 +
|etc
 +
|}
 +
 
 +
(From the table it is also obvious why the treatment with the highest priority is last, it is varied most.)
  
(Av tabellen framgår också varför åtgärden med högst prioritet ligger sist, den varieras helt enkelt mest.)
 
 
=== Creating Generation  2-n ===
 
=== Creating Generation  2-n ===
Första gången generation 2 skapas måste den simuleras fram, men när skötselprogramgeneratorn skapar fler alternativ för generation 1 och senare generationer kan specifikationer och resultat återanvändas. Det går till så här:
 
När en generation är klar sparas skötselspecifikationen som användes undan om den hör till en komplett generation. Specifikationerna sparas per kontrollkategori, och uppdelat beroende på om generationen startade med träd från föregående generation eller ej. Vidare sorteras specifikationerna efter högsta nuvärde. Till exempel kan det vara undansparat att för kontrollkategorin granskogsskötsel för skog utan fröträd/skärm ger röjning i period 4, gallring i period 8 och slutavverkning i period 11 högsta nuvärdet.
 
När en ny generation ska skapas utvärderar man hur det ska göras, detta beror på följande villkor:
 
 
 
 
 
Beroende på dessa villkor kan något av följande ske:
 
 
 
 
För de två första fallen finns dels varianten att man helt enkelt kopierar resultat eller specifikationer från föregående generation (i detta fall skapas bara ett alternativ), eller att man kopierar från flera tidigare uträkningar (i detta fall skapas flera alternativ). Det förstnämna görs typiskt för generation 3 och framåt, det sistnämnda när generation 2 ska skapas för alternativ 2 och framåt av generation 1.
 
Beskrivning Föregående komplett Samma kontrollkategori Samma tillstånd kvarhållna träd Anrop från beståndsvis Kopiera Spec Kopiera Resultat Flera alternaiv skapas
 
CopyPreviousGeneration J J J N - J N
 
RepeatPreviousGeneration J J N - J - N
 
CopyBestSaved N J J N - J J
 
BestSaved N J N - J - J
 
GenerateNew - N - - - - J
 
  
Exempel på hur detta kan ske:
+
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.
Generation 1 Generation 2 Generation 3-n Kommentar
+
 
Gen 1 Alt 1 skapas Gen 2 alt 1 skapas, specifikation sparas Gen 2 alt 1 kopieras Resultat från generation 2 kopieras till generation 3
+
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.
Gen 2 alt 2 skapas, specifikation sparas Gen 2 alt 2 kopieras Anta att detta alternativ har högre nuvärde, då sparas det först
+
 
Gen 1 Alt 2 skapas Gen 2 Alt 2 kopieras (skapas redan vid kopiering av gen 2) Bästa resultatet kopieras först.  
+
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.
Gen 2 Alt 1 kopieras (skapas redan vid kopiering av gen 2) Näst bästa resultatet kopieras
+
 
 +
Also, treatment programs are saved when they are complete.
 +
 
 +
So when a new generation is to be started, the following conditions are evaluated:
 +
 
 +
;LateGeneration: Is the generation before this generation complete? (Meaning is this generation 3 or later?)
 +
;SameControlCat: Is the same control category used in the new generation as in the previous generation?
 +
;SameStartState: Did the previous generation and this generation start with the same state regarding seed trees/shelterwood?
 +
;SavedSpecs: Are there saved specifications for the control category to be used by the new generation, with the same state regarding seed trees/shelterwood?
 +
 
 +
The desired methods of creating a new generation are (fastest first, slowest last):
 +
 
 +
;CopyPreviousGeneration: Results are copied from the previous generation. No new simulation required. LateGeneration, SameControlCat, and SameStartState must be true
 +
;RepeatPreviousGeneration: Specification from previous generation is used, new simulation is done. LateGeneration and SameControlCat must be true.
 +
;CopyBestSaved: Several generations are created with result copied from saved treatment programs. No new simulation required. SameControlCat and SavedSpecs, and SameStartState must be true.
 +
;RepeatBestSaved: Several generations are created from saved specifications. New simulations required. SameControlCat and SavedSpecs must be true.
 +
;GenerateNew: Both new specifications and new simulation is done. Used when none of the methods above can be used.
 +
 
 +
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.
 +
 
 +
A treatment program generation typically works like this:
 +
 
 +
# First alternative of generation 1 is simulated.
 +
## First alternative of generation 2 is simulated, specification is saved (GenerateNew)
 +
### Only alternative of generation 3 (CopyPreviousGeneration)
 +
## Second alternative of generation 3 is simulated, specification is saved (GenerateNew)
 +
### Only alternative of generation 3 (CopyPreviousGeneration)
 +
## etc for generation 2-3
 +
# Second alternative of generation 1 is simulated
 +
## Alternatives 1-n for generation 2 are created by coping best alternatives 1-n from first alternative of generation 1 (CopyBestSaved)
 +
 
 +
The example above assumes that each generation either ends with retained trees, or that no generation ends with retained trees.
 +
 
 +
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:
 +
 
 +
{| border="1"
 +
|-
 +
|Generation 1||Generation 2||How is generation done?
 +
|-
 +
|SeedTrees||SeedTrees||As above
 +
|-
 +
|SeedTrees||NoSeedTrees||As above, but Repeat... instead of Copy...
 +
|-
 +
|NoSeedTrees||SeedTrees||As above, but Repeat... instead of Copy...
 +
|-
 +
|NoSeedTrees||NoSeedTrees||As above
 +
 
 +
|}

Latest revision as of 09:32, 26 May 2010

Creating Treatment Programs for an analysis area

The class TreatmentProgramManager manages treatment program generation for an analysis area, as follows:

  1. ForestDomains are evaluated and each treatment unit is assigned to a domain.
  2. For each domain:
    1. Treatment units are set aside for nature conservation
    2. For treatment units that not has been set aside, the TreatmentProgramGenerator is called and treatment programs of the desired types (unmanaged, continuous management, or even aged management, given by the user) are generated
    3. For treatment units that has been set aside, unmanaged treatment programs are generated by the TreatmentProgramGenerator.

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).

Creating Continous Management and Unmanaged Treatment Programs

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.

For continous management, it is evaluated in each period if selection felling is allowed or not. If allowed, selection felling is performed.

Creating Even Aged Treatment Programs

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).

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.

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.

The diagram below illustrates the process for treatment program generation:

Tpg.png

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).

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).

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.

Creating Treatment Specifications

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).

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.

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 TreatmentSpecificationRange. It may look like this:

  1. Cleaning period 4-5
  2. Thinning period 8-10
  3. Final Felling period 10-14

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:

  1. Cleaning period 4-5
  2. Final Felling period 10-14
  3. Thinning period 8-10

The last step is to, from the ranges, create a list of possible specifications. The class TreatmentSpecificationEnumerator creates an enumeration of all possible treatment specifications from the ranges and the class TreatmentSpecificationCollection filters the invalid permutations.

It might look like this:

Cleaning Final Felling Thinning Comment
4 10 8
4 10 9
4 10 10 Filtered since cleaning and final felling not can occur in the same period
4 11 8
4 11 9
4 11 10
5 10 8
etc

(From the table it is also obvious why the treatment with the highest priority is last, it is varied most.)

Creating Generation 2-n

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.

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.

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.

Also, treatment programs are saved when they are complete.

So when a new generation is to be started, the following conditions are evaluated:

LateGeneration
Is the generation before this generation complete? (Meaning is this generation 3 or later?)
SameControlCat
Is the same control category used in the new generation as in the previous generation?
SameStartState
Did the previous generation and this generation start with the same state regarding seed trees/shelterwood?
SavedSpecs
Are there saved specifications for the control category to be used by the new generation, with the same state regarding seed trees/shelterwood?

The desired methods of creating a new generation are (fastest first, slowest last):

CopyPreviousGeneration
Results are copied from the previous generation. No new simulation required. LateGeneration, SameControlCat, and SameStartState must be true
RepeatPreviousGeneration
Specification from previous generation is used, new simulation is done. LateGeneration and SameControlCat must be true.
CopyBestSaved
Several generations are created with result copied from saved treatment programs. No new simulation required. SameControlCat and SavedSpecs, and SameStartState must be true.
RepeatBestSaved
Several generations are created from saved specifications. New simulations required. SameControlCat and SavedSpecs must be true.
GenerateNew
Both new specifications and new simulation is done. Used when none of the methods above can be used.

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.

A treatment program generation typically works like this:

  1. First alternative of generation 1 is simulated.
    1. First alternative of generation 2 is simulated, specification is saved (GenerateNew)
      1. Only alternative of generation 3 (CopyPreviousGeneration)
    2. Second alternative of generation 3 is simulated, specification is saved (GenerateNew)
      1. Only alternative of generation 3 (CopyPreviousGeneration)
    3. etc for generation 2-3
  2. Second alternative of generation 1 is simulated
    1. Alternatives 1-n for generation 2 are created by coping best alternatives 1-n from first alternative of generation 1 (CopyBestSaved)

The example above assumes that each generation either ends with retained trees, or that no generation ends with retained trees.

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:

Generation 1 Generation 2 How is generation done?
SeedTrees SeedTrees As above
SeedTrees NoSeedTrees As above, but Repeat... instead of Copy...
NoSeedTrees SeedTrees As above, but Repeat... instead of Copy...
NoSeedTrees NoSeedTrees As above