Up language level to Java 1.8.
Fix Population serialization/deserialization closes #38
This commit is contained in:
		
							
								
								
									
										4
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								pom.xml
									
									
									
									
									
								
							@@ -68,8 +68,8 @@
 | 
				
			|||||||
        <artifactId>maven-compiler-plugin</artifactId>
 | 
					        <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
        <version>2.3.2</version>
 | 
					        <version>2.3.2</version>
 | 
				
			||||||
        <configuration>
 | 
					        <configuration>
 | 
				
			||||||
          <source>1.7</source>
 | 
					          <source>1.8</source>
 | 
				
			||||||
          <target>1.7</target>
 | 
					          <target>1.8</target>
 | 
				
			||||||
        </configuration>
 | 
					        </configuration>
 | 
				
			||||||
      </plugin>      
 | 
					      </plugin>      
 | 
				
			||||||
      <plugin>
 | 
					      <plugin>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,6 +80,7 @@ public class JTextoutputFrame implements JTextoutputFrameInterface, ActionListen
 | 
				
			|||||||
        textArea.setCaretPosition(0);
 | 
					        textArea.setCaretPosition(0);
 | 
				
			||||||
        textArea.setTabSize(16);
 | 
					        textArea.setTabSize(16);
 | 
				
			||||||
        textArea.setFont(new Font("Courier New", Font.PLAIN, 12));
 | 
					        textArea.setFont(new Font("Courier New", Font.PLAIN, 12));
 | 
				
			||||||
 | 
					        // Limit text output to 2500 Lines
 | 
				
			||||||
        ((AbstractDocument)textArea.getDocument()).setDocumentFilter(new LineBufferDocumentFilter(textArea, 2500));
 | 
					        ((AbstractDocument)textArea.getDocument()).setDocumentFilter(new LineBufferDocumentFilter(textArea, 2500));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import eva2.optimization.strategies.InterfaceOptimizer;
 | 
				
			|||||||
import eva2.problems.F1Problem;
 | 
					import eva2.problems.F1Problem;
 | 
				
			||||||
import eva2.problems.InterfaceOptimizationProblem;
 | 
					import eva2.problems.InterfaceOptimizationProblem;
 | 
				
			||||||
import eva2.util.annotation.Description;
 | 
					import eva2.util.annotation.Description;
 | 
				
			||||||
 | 
					import eva2.yaml.OptimizationConstructor;
 | 
				
			||||||
import org.yaml.snakeyaml.Yaml;
 | 
					import org.yaml.snakeyaml.Yaml;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.FileInputStream;
 | 
					import java.io.FileInputStream;
 | 
				
			||||||
@@ -45,7 +46,7 @@ public class OptimizationParameters extends AbstractOptimizationParameters imple
 | 
				
			|||||||
        OptimizationParameters instance = null;
 | 
					        OptimizationParameters instance = null;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            FileInputStream fileStream = new FileInputStream(yamlFile);
 | 
					            FileInputStream fileStream = new FileInputStream(yamlFile);
 | 
				
			||||||
            instance = (OptimizationParameters) new Yaml().load(fileStream);
 | 
					            instance = (OptimizationParameters) new Yaml(new OptimizationConstructor()).load(fileStream);
 | 
				
			||||||
        } catch (Exception ex) {
 | 
					        } catch (Exception ex) {
 | 
				
			||||||
            System.out.println(ex.getStackTrace() + "\n" + ex.getMessage());
 | 
					            System.out.println(ex.getStackTrace() + "\n" + ex.getMessage());
 | 
				
			||||||
            LOGGER.log(Level.INFO, "Could not load OptimizationParameters.yml.", ex);
 | 
					            LOGGER.log(Level.INFO, "Could not load OptimizationParameters.yml.", ex);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import org.yaml.snakeyaml.Yaml;
 | 
				
			|||||||
import org.yaml.snakeyaml.error.YAMLException;
 | 
					import org.yaml.snakeyaml.error.YAMLException;
 | 
				
			||||||
import org.yaml.snakeyaml.introspector.Property;
 | 
					import org.yaml.snakeyaml.introspector.Property;
 | 
				
			||||||
import org.yaml.snakeyaml.nodes.Node;
 | 
					import org.yaml.snakeyaml.nodes.Node;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.nodes.Tag;
 | 
				
			||||||
import org.yaml.snakeyaml.representer.Represent;
 | 
					import org.yaml.snakeyaml.representer.Represent;
 | 
				
			||||||
import org.yaml.snakeyaml.representer.Representer;
 | 
					import org.yaml.snakeyaml.representer.Representer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,6 +40,7 @@ public class BeanSerializer {
 | 
				
			|||||||
class OptimizationRepresenter extends Representer {
 | 
					class OptimizationRepresenter extends Representer {
 | 
				
			||||||
    public OptimizationRepresenter() {
 | 
					    public OptimizationRepresenter() {
 | 
				
			||||||
        this.representers.put(Population.class, new RepresentPopulation());
 | 
					        this.representers.put(Population.class, new RepresentPopulation());
 | 
				
			||||||
 | 
					        this.addClassTag(Population.class, new Tag("!population"));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -71,7 +73,6 @@ class OptimizationRepresenter extends Representer {
 | 
				
			|||||||
    private class RepresentPopulation implements Represent {
 | 
					    private class RepresentPopulation implements Represent {
 | 
				
			||||||
        public Node representData(Object data) {
 | 
					        public Node representData(Object data) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
 | 
					 | 
				
			||||||
                return representJavaBean(getProperties(data.getClass()), data);
 | 
					                return representJavaBean(getProperties(data.getClass()), data);
 | 
				
			||||||
            } catch (IntrospectionException var3) {
 | 
					            } catch (IntrospectionException var3) {
 | 
				
			||||||
                throw new YAMLException(var3);
 | 
					                throw new YAMLException(var3);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										43
									
								
								src/eva2/yaml/OptimizationConstructor.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/eva2/yaml/OptimizationConstructor.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					package eva2.yaml;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;
 | 
				
			||||||
 | 
					import eva2.optimization.population.Population;
 | 
				
			||||||
 | 
					import eva2.optimization.population.PopulationInitMethod;
 | 
				
			||||||
 | 
					import eva2.tools.Pair;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.constructor.AbstractConstruct;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.constructor.Constructor;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.nodes.MappingNode;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.nodes.Node;
 | 
				
			||||||
 | 
					import org.yaml.snakeyaml.nodes.Tag;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by fabian on 07/12/15.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class OptimizationConstructor extends Constructor {
 | 
				
			||||||
 | 
					    public OptimizationConstructor() {
 | 
				
			||||||
 | 
					        this.yamlConstructors.put(new Tag("!population"), new ConstructPopulation());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private class ConstructPopulation extends AbstractConstruct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public Object construct(Node node) {
 | 
				
			||||||
 | 
					            Population pop = new Population();
 | 
				
			||||||
 | 
					            Map<Object, Object> values = constructMapping((MappingNode)node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            pop.setInitAround((Double) values.get("initAround"));
 | 
				
			||||||
 | 
					            pop.setInitMethod(PopulationInitMethod.valueOf((String) values.get("initMethod")));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ArrayList<Double> initPos = (ArrayList<Double>) values.get("initPos");
 | 
				
			||||||
 | 
					            pop.setInitPos(initPos.stream().mapToDouble(Double::doubleValue).toArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            pop.setPopMetric((InterfaceDistanceMetric) values.get("popMetric"));
 | 
				
			||||||
 | 
					            //pop.setSeedCardinality((Pair<Integer, Integer>) values.get("seedCardinality"));
 | 
				
			||||||
 | 
					            pop.setTargetSize((Integer) values.get("targetSize"));
 | 
				
			||||||
 | 
					            return pop;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user