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

COVERAGE SUMMARY FOR SOURCE FILE [OptimisationJob.java]

nameclass, %method, %block, %line, %
OptimisationJob.java0%   (0/1)0%   (0/8)0%   (0/210)0%   (0/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OptimisationJob0%   (0/1)0%   (0/8)0%   (0/210)0%   (0/46)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/3)
OptimisationJob (DSEWorkflowConfiguration, DSELaunch): void 0%   (0/1)0%   (0/10)0%   (0/4)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/160)0%   (0/29)
fillCacheWithValues (String): List 0%   (0/1)0%   (0/5)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getPCMInstance (): PCMInstance 0%   (0/1)0%   (0/22)0%   (0/5)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
setBlackboard (MDSDBlackboard): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.dsexplore.launch;
2 
3import java.util.ArrayList;
4import java.util.List;
5 
6import org.apache.log4j.Logger;
7import org.eclipse.core.runtime.CoreException;
8import org.eclipse.core.runtime.IProgressMonitor;
9 
10import de.uka.ipd.sdq.dsexplore.analysis.IAnalysis;
11import de.uka.ipd.sdq.dsexplore.helper.GenotypeReader;
12import de.uka.ipd.sdq.dsexplore.opt4j.genotype.DesignDecisionGenotype;
13import de.uka.ipd.sdq.dsexplore.opt4j.optimizer.PredefinedInstanceEvaluator;
14import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividual;
15import de.uka.ipd.sdq.dsexplore.opt4j.start.Opt4JStarter;
16import de.uka.ipd.sdq.pcmsolver.models.PCMInstance;
17import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
18import de.uka.ipd.sdq.workflow.IJob;
19import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
20import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
21import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
22import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
23import de.uka.ipd.sdq.workflow.pcm.blackboard.PCMResourceSetPartition;
24 
25public class OptimisationJob implements IJob, IBlackboardInteractingJob<MDSDBlackboard> {
26        
27        /** Logger for log4j. */
28        private static Logger logger = 
29                Logger.getLogger("de.uka.ipd.sdq.dsexplore.launch.OptimisationJob");
30 
31        private PCMInstance pcmInstance;
32        private List<IAnalysis> evaluators;
33        private Long startTimestampMillis;
34        
35        private MDSDBlackboard blackboard;
36        
37        private DSEWorkflowConfiguration dseConfig;
38            
39 
40        public OptimisationJob(DSEWorkflowConfiguration config, DSELaunch launch) {
41                
42                    this.dseConfig = config;
43                    
44                    this.evaluators = config.getEvaluators();
45        }
46 
47 
48 
49        @Override
50        public void execute(IProgressMonitor monitor) throws JobFailedException,
51                        UserCanceledException {
52                
53                startTimestampMillis = System.currentTimeMillis();
54                
55                logger.debug("Starting...");
56 
57                try{
58                logger.debug("\n Launching optimization with \n"+
59                                "maximal number of iterations: "+this.dseConfig.getMaxIterations()+"\n"+
60                                "individuals per generation:" +this.dseConfig.getIndividualsPerGeneration()+"\n"+
61                                "offspring per generation: individuals per generation / 2 rounded up.");
62                
63                pcmInstance = getPCMInstance();
64            List<PCMInstance> instances = new ArrayList<PCMInstance>();
65            instances.add(pcmInstance);
66            
67            Opt4JStarter.init(evaluators, this.dseConfig,getPCMInstance(), monitor, this.blackboard);
68            
69            if (this.dseConfig.hasCacheInstances()){
70                    fillCacheWithValues(this.dseConfig.getCacheInstancesFileName());
71            }
72            
73                //TODO: extract this in a Builder?
74            if (this.dseConfig.isOptimise()){//use predefined instances as initial population
75                    List<DesignDecisionGenotype> genotypes = GenotypeReader.getGenotypes(this.dseConfig.getPredefinedInstancesFileName(), this.blackboard);
76 
77                    //read in all candidates file if there and add to cache
78                    List<DesignDecisionGenotype> allCandidates = GenotypeReader.getGenotypes(this.dseConfig.getPredefinedAllCandidatesFileName(), this.blackboard);
79 
80                    // read in archive candidates file if there and add to cache. 
81                    // Need to add them to Opt4J archive to ensure a proper continuation of an evolutionary search.
82                    // The addition is done by Opt4JStarter (see below)
83                    List<DesignDecisionGenotype> archiveCandidates = GenotypeReader.getGenotypes(this.dseConfig.getArchiveCandidateFileName(), this.blackboard);
84 
85                    Opt4JStarter.runOpt4JWithPopulation(this.dseConfig, monitor, genotypes, allCandidates, archiveCandidates);
86 
87            }
88                } catch (CoreException e){
89                        throw new JobFailedException(e);
90                          
91                } finally {
92                
93                        logger.warn("DSE launch done. It took "+((System.currentTimeMillis()-startTimestampMillis)/1000)+" seconds.");
94                        
95                        try {
96                                /* There was quite some memory allocation at this point (probably),
97                                 * which seemed caused an OutOfMemory quicker than the VM could get 
98                                 * more memory (max perm size had not been reached yet). Thus, make sure
99                                 * here that all memory is freed. */ 
100                                Runtime.getRuntime().gc();
101                                Opt4JStarter.closeTask();
102                                Opt4JStarter.tearDown();
103                                Runtime.getRuntime().gc();
104                        } catch (Exception e){
105                                e.printStackTrace();
106                        }
107 
108                }
109 
110        }
111 
112        private List<DSEIndividual> fillCacheWithValues(String cacheInstancesFileName) throws CoreException {
113                return GenotypeReader.getIndividuals(cacheInstancesFileName, this.blackboard);
114        }
115 
116 
117 
118        @Override
119        public String getName() {
120                return this.getClass().getName();
121        }
122 
123        @Override
124        public void rollback(IProgressMonitor monitor)
125                        throws RollbackFailedException {
126                // TODO Auto-generated method stub
127 
128        }
129 
130 
131 
132        @Override
133        public void setBlackboard(MDSDBlackboard blackboard) {
134                this.blackboard = blackboard;
135                
136        }
137        
138        private PCMInstance getPCMInstance(){
139                if (this.blackboard != null){
140                        return new PCMInstance((PCMResourceSetPartition)this.blackboard.getPartition(MoveInitialPCMModelPartitionJob.INITIAL_PCM_MODEL_PARTITION_ID));
141                } else {
142                        String message = "Internal error: Cannot retrieve PCM model if blackboard is not set. ";
143                        logger.error(message);
144                        throw new UnsupportedOperationException(message);
145                }
146        }
147        
148}

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