View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.experiment.results;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  import java.util.Map;
22  
23  import p3j.misc.math.Matrix2D;
24  import p3j.pppm.parameters.ParameterAssignment;
25  import p3j.pppm.parameters.ParameterInstance;
26  import p3j.simulation.calculation.deterministic.parameters.MigChildParameters;
27  import p3j.simulation.calculation.deterministic.parameters.MigParameters;
28  import p3j.simulation.calculation.deterministic.parameters.NativeParameters;
29  
30  /**
31   * Summary of a single PPPM execution.
32   * 
33   * Created on February 20, 2007
34   * 
35   * @author Christina Bohk
36   * @author Roland Ewald
37   * 
38   */
39  public class ExecutionSummary {
40  
41  	/** The parameter assignments. */
42  	private final Map<ParameterInstance, ParameterAssignment> paramAssignments;
43  
44  	/** Parameters for calculating native population. */
45  	private NativeParameters nativeParameters;
46  
47  	/** Results of native population calculation. */
48  	private BasicResults nativeResults;
49  
50  	/** Results of emigrant population calculation. */
51  	private List<BasicResults> emigrantResults = new ArrayList<BasicResults>();
52  
53  	/** Parameters to calculate first emigrant generation. */
54  	private MigParameters firstEmigrantParameters;
55  
56  	/** Parameters to calculate child generations of emigrants. */
57  	private List<MigChildParameters> emigrantParameters = new ArrayList<MigChildParameters>();
58  
59  	/** Results of immigrant population calculation. */
60  	private List<BasicResults> immigrantResults = new ArrayList<BasicResults>();
61  
62  	/** Parameters to calculate first immigrant generation. */
63  	private MigParameters firstImmigrantParameters;
64  
65  	/** Parameters to calculate child generations of immigrants. */
66  	private List<MigChildParameters> immigrantParameters = new ArrayList<MigChildParameters>();
67  
68  	/**
69  	 * Instantiates a new execution summary.
70  	 * 
71  	 * @param assignment
72  	 *          the overall assignment used: parameter instance -> assignment
73  	 */
74  	public ExecutionSummary(Map<ParameterInstance, ParameterAssignment> assignment) {
75  		paramAssignments = Collections.unmodifiableMap(assignment);
76  	}
77  
78  	public List<MigChildParameters> getEmigrantParameters() {
79  		return emigrantParameters;
80  	}
81  
82  	public void setEmigrantParameters(List<MigChildParameters> emigrantParameters) {
83  		this.emigrantParameters = emigrantParameters;
84  	}
85  
86  	/**
87  	 * Adds the emigrant parameters.
88  	 * 
89  	 * @param parameters
90  	 *          the parameters
91  	 */
92  	public void addEmigrantParameters(MigChildParameters parameters) {
93  		this.emigrantParameters.add(parameters);
94  	}
95  
96  	public MigParameters getFirstEmigrantParameters() {
97  		return firstEmigrantParameters;
98  	}
99  
100 	public void setFirstEmigrantParameters(MigParameters firstEmigrantParameters) {
101 		this.firstEmigrantParameters = firstEmigrantParameters;
102 	}
103 
104 	public MigParameters getFirstImmigrantParameters() {
105 		return firstImmigrantParameters;
106 	}
107 
108 	public void setFirstImmigrantParameters(MigParameters firstImmigrantParameters) {
109 		this.firstImmigrantParameters = firstImmigrantParameters;
110 	}
111 
112 	public List<MigChildParameters> getImmigrantParameters() {
113 		return immigrantParameters;
114 	}
115 
116 	public void setImmigrantParameters(
117 	    List<MigChildParameters> immigrantParameters) {
118 		this.immigrantParameters = immigrantParameters;
119 	}
120 
121 	/**
122 	 * Adds the immigrant parameter.
123 	 * 
124 	 * @param parameters
125 	 *          the parameters
126 	 */
127 	public void addImmigrantParameter(MigChildParameters parameters) {
128 		this.immigrantParameters.add(parameters);
129 	}
130 
131 	public NativeParameters getNativeParameters() {
132 		return nativeParameters;
133 	}
134 
135 	public void setNativeParameters(NativeParameters nativeParameters) {
136 		this.nativeParameters = nativeParameters;
137 	}
138 
139 	public List<BasicResults> getEmigrantResults() {
140 		return emigrantResults;
141 	}
142 
143 	public void setEmigrantResults(List<BasicResults> emigrantResults) {
144 		this.emigrantResults = emigrantResults;
145 	}
146 
147 	/**
148 	 * Adds the results for emigrants.
149 	 * 
150 	 * @param emigrantResult
151 	 *          the emigrant results
152 	 */
153 	public void addEmigrantResult(BasicResults emigrantResult) {
154 		this.emigrantResults.add(emigrantResult);
155 	}
156 
157 	public List<BasicResults> getImmigrantResults() {
158 		return immigrantResults;
159 	}
160 
161 	public void setImmigrantResults(List<BasicResults> immigrantResults) {
162 		this.immigrantResults = immigrantResults;
163 	}
164 
165 	/**
166 	 * Adds the results for immigrants.
167 	 * 
168 	 * @param immigrantResult
169 	 *          the immigrant results
170 	 */
171 	public void addImmigrantResult(BasicResults immigrantResult) {
172 		this.immigrantResults.add(immigrantResult);
173 	}
174 
175 	public BasicResults getNativeResults() {
176 		return nativeResults;
177 	}
178 
179 	public void setNativeResults(BasicResults nativeResults) {
180 		this.nativeResults = nativeResults;
181 	}
182 
183 	/**
184 	 * Calculates total end population.
185 	 * 
186 	 * @return total end population
187 	 */
188 	public Matrix2D getTotalEndPopulation() {
189 
190 		// Natives plus immigrants
191 		List<Matrix2D> addList = new ArrayList<Matrix2D>();
192 		addList.add(nativeResults.getEndXm());
193 		addList.add(nativeResults.getEndXf());
194 		for (BasicResults immResults : immigrantResults) {
195 			addList.add(immResults.getEndXm());
196 			addList.add(immResults.getEndXf());
197 		}
198 
199 		// Minus all emigrants
200 		List<Matrix2D> subList = new ArrayList<Matrix2D>();
201 		for (BasicResults emResults : emigrantResults) {
202 			subList.add(emResults.getEndXm());
203 			subList.add(emResults.getEndXf());
204 		}
205 
206 		return Matrix2D.add(addList).sub(subList);
207 	}
208 
209 	public Map<ParameterInstance, ParameterAssignment> getParamAssignments() {
210 		return paramAssignments;
211 	}
212 }