EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.dsexplore.opt4j.representation]

COVERAGE SUMMARY FOR SOURCE FILE [DSEProblem.java]

nameclass, %method, %block, %line, %
DSEProblem.java0%   (0/1)0%   (0/21)0%   (0/889)0%   (0/201)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DSEProblem0%   (0/1)0%   (0/21)0%   (0/889)0%   (0/201)
DSEProblem (DSEWorkflowConfiguration, PCMInstance): void 0%   (0/1)0%   (0/38)0%   (0/13)
determineAllocationDecisions (List, DesignDecisionGenotype): void 0%   (0/1)0%   (0/53)0%   (0/12)
determineAssembledComponentsDecisions (List, DesignDecisionGenotype): void 0%   (0/1)0%   (0/42)0%   (0/10)
determineCapacityDecisions (List, DesignDecisionGenotype): void 0%   (0/1)0%   (0/89)0%   (0/18)
determineInitialGenotype (DecisionSpace): List 0%   (0/1)0%   (0/344)0%   (0/78)
determineProcessingRateDecisions (List, DesignDecisionGenotype): void 0%   (0/1)0%   (0/79)0%   (0/17)
getDegree (Entity, Class): DegreeOfFreedomInstance 0%   (0/1)0%   (0/28)0%   (0/5)
getDesignDecision (int): DegreeOfFreedomInstance 0%   (0/1)0%   (0/7)0%   (0/1)
getDesignDecisions (): List 0%   (0/1)0%   (0/4)0%   (0/1)
getEMFProblem (): DecisionSpace 0%   (0/1)0%   (0/3)0%   (0/1)
getGenotypeOfInitialPCMInstance (): DesignDecisionGenotype 0%   (0/1)0%   (0/3)0%   (0/1)
getInitialGenotypeList (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getInitialInstance (): PCMInstance 0%   (0/1)0%   (0/3)0%   (0/1)
getProcessingResourceSpec (ProcessingResourceDegree): ProcessingResourceSpeci... 0%   (0/1)0%   (0/33)0%   (0/9)
initialiseProblem (): void 0%   (0/1)0%   (0/40)0%   (0/10)
loadProblem (): DecisionSpace 0%   (0/1)0%   (0/8)0%   (0/2)
loadProblem (String): DecisionSpace 0%   (0/1)0%   (0/50)0%   (0/9)
saveProblem (): void 0%   (0/1)0%   (0/9)0%   (0/3)
setInitialPopulation (List): void 0%   (0/1)0%   (0/8)0%   (0/3)
throwUnknownDegreeException (DegreeOfFreedomInstance): void 0%   (0/1)0%   (0/14)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/31)0%   (0/5)

1package de.uka.ipd.sdq.dsexplore.opt4j.representation;
2 
3 
4import java.util.ArrayList;
5import java.util.List;
6 
7import org.eclipse.core.runtime.CoreException;
8import org.eclipse.core.runtime.Status;
9import org.eclipse.emf.ecore.EObject;
10import org.eclipse.emf.ecore.resource.ResourceSet;
11import org.eclipse.emf.ecore.util.EcoreUtil;
12 
13import de.uka.ipd.sdq.dsexplore.designdecisions.alternativecomponents.AlternativeComponent;
14import de.uka.ipd.sdq.dsexplore.exception.ChoiceOutOfBoundsException;
15import de.uka.ipd.sdq.dsexplore.helper.DegreeOfFreedomHelper;
16import de.uka.ipd.sdq.dsexplore.helper.EMFHelper;
17import de.uka.ipd.sdq.dsexplore.helper.FixDesignDecisionReferenceSwitch;
18import de.uka.ipd.sdq.dsexplore.launch.DSEWorkflowConfiguration;
19import de.uka.ipd.sdq.dsexplore.opt4j.genotype.DesignDecisionGenotype;
20import de.uka.ipd.sdq.dsexplore.opt4j.start.Opt4JStarter;
21import de.uka.ipd.sdq.pcm.allocation.AllocationContext;
22import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext;
23import de.uka.ipd.sdq.pcm.core.entity.Entity;
24import de.uka.ipd.sdq.pcm.cost.helper.CostUtil;
25import de.uka.ipd.sdq.pcm.designdecision.AllocationDegree;
26import de.uka.ipd.sdq.pcm.designdecision.AssembledComponentDegree;
27import de.uka.ipd.sdq.pcm.designdecision.CapacityDegree;
28import de.uka.ipd.sdq.pcm.designdecision.ContinousRangeChoice;
29import de.uka.ipd.sdq.pcm.designdecision.ContinuousProcessingRateDegree;
30import de.uka.ipd.sdq.pcm.designdecision.ContinuousRangeDegree;
31import de.uka.ipd.sdq.pcm.designdecision.DecisionSpace;
32import de.uka.ipd.sdq.pcm.designdecision.DegreeOfFreedomInstance;
33import de.uka.ipd.sdq.pcm.designdecision.DiscreteDegree;
34import de.uka.ipd.sdq.pcm.designdecision.DiscreteProcessingRateDegree;
35import de.uka.ipd.sdq.pcm.designdecision.DiscreteRangeChoice;
36import de.uka.ipd.sdq.pcm.designdecision.DiscreteRangeDegree;
37import de.uka.ipd.sdq.pcm.designdecision.ClassChoice;
38import de.uka.ipd.sdq.pcm.designdecision.ClassDegree;
39import de.uka.ipd.sdq.pcm.designdecision.NumberOfCoresDegree;
40import de.uka.ipd.sdq.pcm.designdecision.ProcessingResourceDegree;
41import de.uka.ipd.sdq.pcm.designdecision.ResourceContainerReplicationDegree;
42import de.uka.ipd.sdq.pcm.designdecision.SchedulingPolicyChoice;
43import de.uka.ipd.sdq.pcm.designdecision.SchedulingPolicyDegree;
44import de.uka.ipd.sdq.pcm.designdecision.designdecisionFactory;
45import de.uka.ipd.sdq.pcm.designdecision.impl.designdecisionFactoryImpl;
46import de.uka.ipd.sdq.pcm.repository.BasicComponent;
47import de.uka.ipd.sdq.pcm.repository.PassiveResource;
48import de.uka.ipd.sdq.pcm.repository.Repository;
49import de.uka.ipd.sdq.pcm.repository.RepositoryComponent;
50import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification;
51import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer;
52import de.uka.ipd.sdq.pcm.resourceenvironment.SchedulingPolicy;
53import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType;
54import de.uka.ipd.sdq.pcmsolver.models.PCMInstance;
55 
56/**
57 * The {@link DSEProblem} defines the problem. Therefore, it reads in the 
58 * current PCM instances and identifies the available design options to define 
59 * the design space. 
60 * 
61 * @author Anne
62 *
63 */
64public class DSEProblem {
65        
66        /**
67         * Is changed during the evaluation, as the decisions refer to it.
68         */
69        private PCMInstance initialInstance;
70        
71        private DecisionSpace pcmProblem;
72        private designdecisionFactory designDecisionFactory;
73        
74 
75        private List<DesignDecisionGenotype> initialGenotypeList = null;
76 
77        private DSEWorkflowConfiguration dseConfig;
78 
79        private DesignDecisionGenotype initialGenotype;
80 
81        
82        /**
83         * @param pcmInstance
84         * @throws CoreException 
85         */
86        public DSEProblem(DSEWorkflowConfiguration dseConfig, PCMInstance pcmInstance) throws CoreException{
87                this.dseConfig = dseConfig;
88                
89                boolean newProblem = dseConfig.isNewProblem();
90                this.initialInstance = pcmInstance;
91                
92                this.designDecisionFactory = designdecisionFactoryImpl.init();
93                
94                if (newProblem){
95                        initialiseProblem();
96                } else {
97                        //Alternative Component has to be called to create the mapping for all AssemblyContexts and their roles, 
98                        //in order to be able to exchange implementations later. The design decisions calculated here are not kept, only
99                        //the mapping inside AlternativeComponent.getInstance()
100                        AlternativeComponent.getInstance().generateDesignDecisions(pcmInstance);
101                        DecisionSpace problem = loadProblem();
102                        this.pcmProblem = problem;
103                        this.initialGenotypeList = determineInitialGenotype(problem);
104                }
105                
106                //TODO: mapping of design decisions to bounds. 
107                /*
108                 * Meta model design decisions?? Each design decision would know its
109                 * bounds and the annotated element or more specific the annotated
110                 * property of this element that is exactly the value range than the
111                 * bound of the decision. 
112                 * 
113                 * But what about the genotype? With a ordered list
114                 * of design decisions, I can map the genotype entry to a design
115                 * decisions. Better group in integer and double, then. -> require CompositeGenotype
116                 * 
117                 * Also meta-model the genotype as a choice within the range.
118                 */                
119        }
120        
121        private DecisionSpace loadProblem() throws CoreException {
122                String filename = this.dseConfig.getDesignDecisionFileName();
123                return this.loadProblem(filename);
124        }
125        
126        private DecisionSpace loadProblem(String filename) throws CoreException{
127                ResourceSet pcmResourceSet = this.initialInstance.getAllocation().eResource().getResourceSet();
128                
129                EObject eproblem = EMFHelper.loadFromXMIFile(filename, pcmResourceSet);
130                if (!(eproblem instanceof DecisionSpace)){
131                        throw new CoreException(new Status(Status.ERROR, "de.uka.ipd.sdq.dsexplore", 0, "Cannot read design decision file "+filename+". Please create a new one.", null));
132                }
133                DecisionSpace problem = (DecisionSpace)eproblem;
134                //Adjust references with the right loaded model objects in memory?
135 
136                FixDesignDecisionReferenceSwitch visitor = new FixDesignDecisionReferenceSwitch(this.initialInstance);
137                visitor.doSwitch(problem);
138                
139                EcoreUtil.resolveAll(eproblem);
140                
141                return problem;
142        }
143 
144 
145        private List<DesignDecisionGenotype> determineInitialGenotype(DecisionSpace problem) {
146                DesignDecisionGenotype genotype = new DesignDecisionGenotype();
147                
148                for (DegreeOfFreedomInstance dd : problem.getDegreesOfFreedom()) {
149                        if (dd instanceof ClassDegree){
150 
151                                ClassChoice choice = this.designDecisionFactory.createClassChoice();
152                                choice.setDegreeOfFreedomInstance(dd);
153 
154                                if (dd instanceof AssembledComponentDegree){
155                                        AssembledComponentDegree acd = (AssembledComponentDegree)dd;
156                                        AssemblyContext ac = (AssemblyContext)acd.getPrimaryChanged();
157                                        RepositoryComponent rc = ac.getEncapsulatedComponent__AssemblyContext();
158                                        choice.setChosenValue(rc);
159                                } else if (dd instanceof AllocationDegree){
160                                        AllocationDegree ad = (AllocationDegree)dd;
161                                        AllocationContext ac = (AllocationContext)ad.getPrimaryChanged();
162                                        ResourceContainer rc = ac.getResourceContainer_AllocationContext();
163                                        choice.setChosenValue(rc);
164                                } else throwUnknownDegreeException(dd);
165                                
166                                //check if entity is in the domain
167                                if (!EMFHelper.contains(((ClassDegree) dd).getClassDesignOptions(), choice.getChosenValue())){
168                                        throw new ChoiceOutOfBoundsException(choice, "Error when determining initial genotype"); 
169                                }
170                                
171                                genotype.add(choice);
172                        } else if (dd instanceof ContinuousRangeDegree){
173                                
174                                ContinousRangeChoice choice = this.designDecisionFactory.createContinousRangeChoice();
175                                choice.setDegreeOfFreedomInstance(dd);
176                                
177                                if (dd instanceof ContinuousProcessingRateDegree){
178                                        ContinuousProcessingRateDegree prd = (ContinuousProcessingRateDegree)dd;
179                                        
180                                        ProcessingResourceSpecification rightPrs = getProcessingResourceSpec(prd);
181 
182                                        if (rightPrs != null){
183                                                double rate = CostUtil.getInstance().getDoubleFromSpecification(rightPrs.getProcessingRate_ProcessingResourceSpecification().getSpecification());
184                                                choice.setChosenValue(rate);
185                                        } else 
186                                                throw new RuntimeException("Invalid degree of freedom "+dd.toString()+". The referenced ProcessingResourceType is not available in the given ResourceContainer.");
187                                } else throwUnknownDegreeException(dd);
188                                
189                                genotype.add(choice);
190                        } else if (dd instanceof SchedulingPolicyDegree){
191                                
192                                SchedulingPolicyChoice schedChoice = this.designDecisionFactory.createSchedulingPolicyChoice();
193                                schedChoice.setDegreeOfFreedomInstance(dd);
194                                
195                                ProcessingResourceType procType = ((SchedulingPolicyDegree)dd).getProcessingresourcetype();
196                                ResourceContainer rc = (ResourceContainer)dd.getPrimaryChanged();
197                                
198                                SchedulingPolicy policy = null;
199                                
200                                for (ProcessingResourceSpecification proc : rc.getActiveResourceSpecifications_ResourceContainer()) {
201                                        if (EMFHelper.checkIdentity(proc.getActiveResourceType_ActiveResourceSpecification(),procType)){
202                                                policy = proc.getSchedulingPolicy();
203                                                break;
204                                        }
205                                }
206                                if (policy == null){
207                                        throw new RuntimeException("Invalid degree of freedom "+dd.toString()+". The referenced ProcessingResourceType is not available in the given ResourceContainer.");
208                                }
209                                schedChoice.setChosenValue(policy);
210                                genotype.add(schedChoice);
211                                
212                        } else if (dd instanceof DiscreteDegree){
213                                DiscreteDegree degree = (DiscreteDegree)dd;
214                                
215                                DiscreteRangeChoice choice = this.designDecisionFactory.createDiscreteRangeChoice();
216                                choice.setDegreeOfFreedomInstance(degree);
217                                
218                                EObject entity = degree.getPrimaryChanged();
219                                
220                                if (degree instanceof CapacityDegree){
221                                        PassiveResource pr = (PassiveResource)entity;
222                                        choice.setChosenValue(Integer.valueOf(pr.getCapacity_PassiveResource().getSpecification()));
223                                } else if (degree instanceof NumberOfCoresDegree) {
224                                        ProcessingResourceSpecification prd = getProcessingResourceSpec((ProcessingResourceDegree)degree);
225                                        choice.setChosenValue(prd.getNumberOfReplicas());
226                                } else if (degree instanceof DiscreteProcessingRateDegree){
227                                        
228                                        DiscreteProcessingRateDegree prd = (DiscreteProcessingRateDegree)dd;
229                                        
230                                        ProcessingResourceSpecification rightPrs = getProcessingResourceSpec(prd);
231 
232                                        if (rightPrs != null){
233                                                if (!prd.isLowerBoundIncluded() || !prd.isUpperBoundIncluded()){
234                                                        throw new RuntimeException("Only DiscreteProcessingRateDegrees with upper and lower bound included are supported so far, sorry. ");
235                                                }
236                                                double rate = CostUtil.getInstance().getDoubleFromSpecification(rightPrs.getProcessingRate_ProcessingResourceSpecification().getSpecification());
237                                                double startStep = prd.getFrom();
238                                                double endStep = prd.getTo();
239                                                double stepwidth = (endStep - startStep) / prd.getNumberOfSteps();
240                                                
241                                                double chosenStep = (rate - startStep) / stepwidth;  
242                                                choice.setChosenValue((int)chosenStep);
243                                        } else 
244                                                throw new RuntimeException("Invalid degree of freedom "+dd.toString()+". The referenced ProcessingResourceType is not available in the given ResourceContainer.");
245                                } else if (degree instanceof ResourceContainerReplicationDegree){
246                                        choice.setChosenValue(1);
247                                        
248                                } else throwUnknownDegreeException(dd);
249                                genotype.add(choice);
250                        } else throwUnknownDegreeException(dd);
251                };
252 
253                //determineProcessingRateDecisions(new ArrayList<DesignDecision>(), genotype);
254                //determineAssembledComponentsDecisions(new ArrayList<DesignDecision>(), genotype);
255                //determineAllocationDecisions(new ArrayList<DesignDecision>(), genotype);
256                List<DesignDecisionGenotype> result = new ArrayList<DesignDecisionGenotype>();
257                result.add(genotype);
258                this.initialGenotype = genotype;
259                return result;
260        }
261 
262        private ProcessingResourceSpecification getProcessingResourceSpec(
263                        ProcessingResourceDegree prd) {
264                ResourceContainer rc = (ResourceContainer)prd.getPrimaryChanged();
265                List<ProcessingResourceSpecification> prsList = rc.getActiveResourceSpecifications_ResourceContainer();
266                ProcessingResourceType prt = prd.getProcessingresourcetype();
267 
268                ProcessingResourceSpecification rightPrs = null;
269                for (ProcessingResourceSpecification prs : prsList) {
270                        if (EMFHelper.checkIdentity(prs.getActiveResourceType_ActiveResourceSpecification(),prt)){
271                                rightPrs = prs;
272                                break;
273                        }
274                }
275                return rightPrs;
276        }
277 
278 
279        private void throwUnknownDegreeException(DegreeOfFreedomInstance dd) {
280                throw new RuntimeException("Unknown degree of freedom "+dd.toString()+".");                
281        }
282 
283        /**
284         * Initialises the degrees of freedoms and at the same time determines the initial genotype. 
285         */
286        private void initialiseProblem() {
287                this.pcmProblem = this.designDecisionFactory.createDecisionSpace();
288                List<DegreeOfFreedomInstance> dds = this.pcmProblem.getDegreesOfFreedom();
289                //analyse PCM Instance and create design decisions
290                //TODO: could this be possible with a M2M transformation? 
291                //First, only get design decisions for making resources faster. 
292                this.initialGenotypeList = new ArrayList<DesignDecisionGenotype>();
293                DesignDecisionGenotype initialCandidate = new DesignDecisionGenotype();
294                determineProcessingRateDecisions(dds,initialCandidate);
295                //find equivalent components
296                determineAssembledComponentsDecisions(dds,initialCandidate);
297                determineAllocationDecisions(dds,initialCandidate);
298                //Quickfix: Add a Soap or RMI decision. This is not meta modelled. 
299                //determineSOAPOrRMIDecisions();
300                determineCapacityDecisions(dds,initialCandidate);
301                
302                //TODO: Check if the initial genotype is actually a valid genotype? 
303                //(this may not be the case if the degrees of freedom have been reduced for the optimisation?)
304                
305                
306                this.initialGenotypeList.add(initialCandidate);
307 
308        }
309 
310 
311 
312        /**
313         * Determine Capacity options based on {@link Repository}.
314         * Thus, this may detect {@link PassiveResource}s of components that are not used 
315         * in the system. These need to be deleted manually. 
316         * 
317         * Otherwise, I would have to descend in all composed structures to find all {@link BasicComponent}s.
318         * @param dds
319         * @param initialCandidate
320         */
321        private void determineCapacityDecisions(List<DegreeOfFreedomInstance> dds,
322                        DesignDecisionGenotype genotype) {
323                
324                List<Repository> repositories = this.initialInstance.getRepositories();
325                for (Repository repository : repositories) {
326                        List<RepositoryComponent> components = repository.getComponents__Repository();
327                        for (RepositoryComponent repositoryComponent : components) {
328                                if (repositoryComponent instanceof BasicComponent){
329                                        
330                                        BasicComponent basicComponent = (BasicComponent)repositoryComponent;
331                                        List<PassiveResource> passiveResources = basicComponent.getPassiveResource_BasicComponent();
332                                        for (PassiveResource passiveResource : passiveResources) {
333                                                CapacityDegree capacityDegree = this.designDecisionFactory.createCapacityDegree();
334                                                capacityDegree.setPrimaryChanged(passiveResource);
335                                                capacityDegree.setFrom(1);
336                                                capacityDegree.setTo(Integer.valueOf(passiveResource.getCapacity_PassiveResource().getSpecification()));
337                                                dds.add(capacityDegree);
338                                                
339                                                DiscreteRangeChoice choice = this.designDecisionFactory.createDiscreteRangeChoice();
340                                                choice.setDegreeOfFreedomInstance(capacityDegree);
341                                                choice.setChosenValue(Integer.valueOf(passiveResource.getCapacity_PassiveResource().getSpecification()));
342                                                
343                                                genotype.add(choice);
344                                        }
345                                }
346                        }
347                }
348                
349        }
350 
351        /**
352         * XXX: This is not meta modelled and just a quick fix
353         * 
354         */
355//        private void determineSOAPOrRMIDecisions(List<DesignDecision> dds, DesignDecisionGenotype genotype) {
356//                
357//                Configuration connectorConfig = this.initialInstance.getConnectorConfig();
358//                FeatureConfig featureConfig = connectorConfig.getDefaultConfig();
359//                
360//                ConnectorConfigDecision cd = this.designDecisionFactory.createConnectorConfigDecision();
361//                SoapOrRmi domain = this.designDecisionFactory.createSoapOrRmi();
362//                
363//                cd.setDomain(domain);
364//                cd.setFeatureconfig(featureConfig);
365//                
366//                dds.add(cd);
367//                
368//                //0.0 stands for SOAP, 1.0 for RMI
369//                genotype.add(0.0);
370//                
371//        }
372 
373        //TODO: change this to two visitors that either create the design decision and initial genotype or just initial genotype.  
374        private void determineAllocationDecisions(List<DegreeOfFreedomInstance> dds, DesignDecisionGenotype genotype) {
375                List<AllocationContext> acs = this.initialInstance.getAllocation().getAllocationContexts_Allocation();
376                List<ResourceContainer> rcs = this.initialInstance.getResourceEnvironment().getResourceContainer_ResourceEnvironment();
377                
378                
379                
380                //each allocation context could be allocated on each container.
381                for (AllocationContext ac : acs) {
382                        AllocationDegree ad = this.designDecisionFactory.createAllocationDegree();
383                        ad.setPrimaryChanged(ac);
384                        ad.getClassDesignOptions().addAll(rcs);
385                        dds.add(ad);
386                        
387                        ClassChoice choice = this.designDecisionFactory.createClassChoice();
388                        choice.setDegreeOfFreedomInstance(ad);
389                        choice.setChosenValue(ac.getResourceContainer_AllocationContext());
390                        
391                        genotype.add(choice);
392                }
393                
394                
395                
396        }
397 
398 
399        /**
400         * Be sure to add one design decision and one gene in the initial genotype at once. The index is important.
401         * @param genotypeIndex
402         */
403        private void determineAssembledComponentsDecisions(List<DegreeOfFreedomInstance> dds, DesignDecisionGenotype genotype) {
404                AlternativeComponent ac = AlternativeComponent.getInstance();
405                List<AssembledComponentDegree> decisions = ac.generateDesignDecisions(this.initialInstance);
406                
407                for (AssembledComponentDegree designDecision : decisions) {
408                        dds.add(designDecision);
409                        RepositoryComponent currentlyAssembledComponent = ((AssemblyContext)designDecision.getPrimaryChanged()).getEncapsulatedComponent__AssemblyContext();
410                        
411                        ClassChoice choice = this.designDecisionFactory.createClassChoice();
412                        choice.setDegreeOfFreedomInstance(designDecision);
413                        choice.setChosenValue(currentlyAssembledComponent);
414                        genotype.add(choice);
415                        
416                }
417 
418        }
419 
420        /**
421         * Be sure to add one design decision and one gene in the initial genotype at once. The index is important.
422         * Creates {@link ContinuousProcessingRateDegree} decisions for each found processing resource.
423         * 
424         * Also determines {@link SchedulingPolicyDegree}s.
425         * 
426         * TODO: make configurable to also add {@link DiscreteProcessingRateDegree}s.
427         */
428        private void determineProcessingRateDecisions(List<DegreeOfFreedomInstance> dds, DesignDecisionGenotype genotype) {
429                List<ResourceContainer> resourceContainers = this.initialInstance.getResourceEnvironment().getResourceContainer_ResourceEnvironment();
430                for (ResourceContainer resourceContainer : resourceContainers) {
431                        List<ProcessingResourceSpecification> resources = resourceContainer.getActiveResourceSpecifications_ResourceContainer();
432                        for (ProcessingResourceSpecification resource : resources) {
433                                
434                                //Create ContinuousProcessingRateDegree
435                                ContinuousProcessingRateDegree decision = this.designDecisionFactory.createContinuousProcessingRateDegree();
436                                decision.setLowerBoundIncluded(false);
437                                double currentRate = CostUtil.getInstance().getDoubleFromSpecification(resource.getProcessingRate_ProcessingResourceSpecification().getSpecification());
438                                //XXX initial assumption: the highest possible processingRate is 10 times the current one.
439                                decision.setTo(currentRate * 2.0);
440                                decision.setFrom(currentRate * 0.5);
441                                decision.setPrimaryChanged(resourceContainer);
442                                decision.setProcessingresourcetype(resource.getActiveResourceType_ActiveResourceSpecification());
443                                dds.add(decision);
444                                
445                                ContinousRangeChoice choice = this.designDecisionFactory.createContinousRangeChoice();
446                                choice.setDegreeOfFreedomInstance(decision);
447                                choice.setChosenValue(currentRate);
448                                
449                                genotype.add(choice);
450                                
451                                //Create SchedulingPolicyDegree (excluded here, not in default problem, can be modelled manually).
452                                /*SchedulingPolicyDegree schedulingDecision = this.designDecisionFactory.createSchedulingPolicyDegree();
453                                SchedulingPolicy currentPolicy = resource.getSchedulingPolicy();
454                                
455                                schedulingDecision.getDomainOfAllowedSchedulingPolicies().add(SchedulingPolicy.FCFS);
456                                schedulingDecision.getDomainOfAllowedSchedulingPolicies().add(SchedulingPolicy.PROCESSOR_SHARING);
457                                schedulingDecision.setPrimaryChanged(resourceContainer);
458                                schedulingDecision.setProcessingresourcetype(resource.getActiveResourceType_ActiveResourceSpecification());
459                                dds.add(schedulingDecision);
460                                
461                                SchedulingPolicyChoice schedulingChoice = this.designDecisionFactory.createSchedulingPolicyChoice();
462                                schedulingChoice.setDegreeOfFreedomInstance(schedulingDecision);
463                                schedulingChoice.setChosenValue(currentPolicy);
464                                
465                                genotype.add(schedulingChoice);*/
466                                
467                                
468                                ;
469                        }
470                }
471        }
472 
473 
474        protected DegreeOfFreedomInstance getDesignDecision(int index){
475                return this.pcmProblem.getDegreesOfFreedom().get(index);
476        }
477 
478        public List<DegreeOfFreedomInstance> getDesignDecisions(){
479                return this.pcmProblem.getDegreesOfFreedom();
480        }
481 
482 
483        public PCMInstance getInitialInstance() {
484                return this.initialInstance;
485        }
486        
487        public DesignDecisionGenotype getGenotypeOfInitialPCMInstance(){
488                return this.initialGenotype;
489        }
490        
491        protected List<DesignDecisionGenotype> getInitialGenotypeList(){
492                return this.initialGenotypeList;
493        }
494 
495 
496        public void saveProblem() {
497 
498                String filename = this.dseConfig.getDesignDecisionFileName();
499                
500//                resourceSet.getPackageRegistry().put
501//                (designdecisionPackage.eNS_URI, 
502//                 designdecisionPackage.eINSTANCE);
503                
504                EMFHelper.saveToXMIFile(this.pcmProblem, filename);
505                
506        }
507 
508        
509        @Override
510        public String toString(){
511                
512                String result = "";
513                
514                List<DegreeOfFreedomInstance> decisions = this.pcmProblem.getDegreesOfFreedom();
515                for (DegreeOfFreedomInstance designDecision : decisions) {
516                        result += DegreeOfFreedomHelper.getDegreeDescription(designDecision)+";";
517                }
518                
519                return result;
520                
521        }
522 
523        
524        public void setInitialPopulation(List<DesignDecisionGenotype> population) throws CoreException{
525                this.initialGenotypeList = population;
526                Opt4JStarter.getDSECreator().setNumberOfNotEvaluatedPredefinedOnes(population.size());
527        }
528 
529        /**
530         * Returns the degree of freedom of the type (or subtype) that has the given 
531         * entity as the changeableEntity.  
532         * @param entity
533         * @param degreeClass
534         * @return The matching DegreeOfFreedomInstance from this problem. 
535         */
536        public DegreeOfFreedomInstance getDegree(Entity entity, Class<? extends DegreeOfFreedomInstance> degreeClass){
537                List<DegreeOfFreedomInstance> degrees = this.pcmProblem.getDegreesOfFreedom();
538                for (DegreeOfFreedomInstance DegreeOfFreedomInstance : degrees) {
539                         
540                        if (degreeClass.isInstance(DegreeOfFreedomInstance) && DegreeOfFreedomInstance.getPrimaryChanged().equals(entity)){
541                                return DegreeOfFreedomInstance;
542                        }
543                }
544                return null;
545        }
546        
547        public DecisionSpace getEMFProblem(){
548                return this.pcmProblem;
549        }
550        
551        
552}

[all classes][de.uka.ipd.sdq.dsexplore.opt4j.representation]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov