// Path: edits-core/src/main/java/org/edits/distance/algorithm/EditDistanceAlgorithm.java
// @Data
// @Log4j
// public abstract class EditDistanceAlgorithm implements Serializable, Cloneable {
// 
// 	private static final long serialVersionUID = 1L;
// 	private Matcher matcher;
// 	private boolean normalize;
// 
// 	public EditDistanceAlgorithm() {
// 		normalize = true;
// 		matcher = new DefaultMatcher();
// 	}
// 
// 	@Override
// 	public abstract EditDistanceAlgorithm clone();
// 
// 	public EditDistanceAlgorithm defaultCopy() {
// 		EditDistanceAlgorithm a = instance(this.getClass().getName());
// 		a.setMatcher(getMatcher().copy());
// 		a.setNormalize(normalize);
// 		return a;
// 	}
// 
// 	public double distance(AnnotatedText t, AnnotatedText h, String pairID) {
// 		List<Annotation> w1 = t.getAnnotation();
// 		List<Annotation> w2 = h.getAnnotation();
// 		return distance(w1, w2, t, h, pairID);
// 	}
// 
// 	public abstract double distance(List<Annotation> ta, List<Annotation> ha, AnnotatedText t, AnnotatedText h,
// 			String pairID);
// 
// 	public double init(double dist, double norm) {
// 		if (!normalize)
// 			return dist;
// 		return dist / norm;
// 	}
// 
// 	public EditDistanceAlgorithm instance(String name) {
// 		try {
// 			return (EditDistanceAlgorithm) this.getClass().getClassLoader().loadClass(this.getClass().getName())
// 					.newInstance();
// 		} catch (Exception e) {
// 			log.debug(e);
// 			throw new RuntimeException("Could not load algorithm " + name);
// 		}
// 	}
// }
// 
// Path: edits-core/src/main/java/org/edits/engines/thread/EditsThread.java
// @Log4j
// public abstract class EditsThread<E> {
// 
// 	private boolean finnished = false;
// 	private Iterator<E> iterator;
// 	@Getter
// 	@Setter
// 	private int threads;
// 	private int workers = 0;
// 
// 	public EditsThread() {
// 		Runtime runtime = Runtime.getRuntime();
// 		threads = runtime.availableProcessors();
// 		if (threads > 24)
// 			threads = 24;
// 	}
// 
// 	public EditsThread(int threads_) {
// 		threads = threads_;
// 	}
// 
// 	public synchronized void finnished() {
// 		workers--;
// 		if (workers == 0) {
// 			finnished = true;
// 		}
// 	}
// 
// 	public synchronized void increment() {
// 		workers++;
// 	}
// 
// 	/**
// 	 * @return
// 	 * @throws Exception
// 	 */
// 	public synchronized E next() throws Exception {
// 
// 		if (iterator != null && iterator.hasNext())
// 			return iterator.next();
// 		return null;
// 	}
// 
// 	public abstract void process(E object) throws Exception;
// 
// 	public void start(Iterator<E> iterator_) {
// 		iterator = iterator_;
// 		log.debug("Started with " + threads + " threads");
// 		for (int i = 0; i < threads; i++)
// 			new Worker<E>(this).start();
// 		finnished = false;
// 		try {
// 			while (finnished == false)
// 				Thread.sleep(1000);
// 		} catch (InterruptedException e) {
// 		}
// 		iterator = null;
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedEntailmentPair.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedEntailmentPair", propOrder = { "t", "h" })
// public class AnnotatedEntailmentPair {
// 
// 	public static AnnotatedEntailmentPair create(String t2, String h2, EditsTextAnnotator annotator) throws Exception {
// 		AnnotatedEntailmentPair px = new AnnotatedEntailmentPair();
// 		AnnotatedText at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(t2));
// 		px.getT().add(at);
// 		at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(h2));
// 		px.getH().add(at);
// 		return px;
// 	}
// 
// 	@XmlTransient
// 	private Map<String, String> attributes;
// 	@XmlAttribute
// 	protected String entailment;
// 	@XmlElement
// 	protected List<AnnotatedText> h;
// 	@XmlAttribute
// 	protected String id;
// 
// 	@XmlTransient
// 	private int order;
// 
// 	@XmlElement
// 	protected List<AnnotatedText> t;
// 
// 	@XmlAttribute
// 	protected String task;
// 
// 	public AnnotatedEntailmentPair() {
// 		t = Lists.newArrayList();
// 		h = Lists.newArrayList();
// 		attributes = Maps.newHashMap();
// 	}
// 
// }


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.extern.log4j.Log4j;
import org.edits.distance.algorithm.EditDistanceAlgorithm;
import org.edits.engines.thread.EditsThread;
import org.edits.etaf.AnnotatedEntailmentPair;
import org.jgap.Chromosome;
import org.jgap.Configuration;
import org.jgap.Genotype;
import org.jgap.IChromosome;
import org.jgap.impl.BooleanGene;
import org.jgap.impl.DefaultConfiguration;
import org.jgap.impl.DoubleGene;
import org.jgap.impl.job.MaxFunction;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.AtomicDouble;
package org.edits.genetic;





@Log4j
public class OptimizeDistance extends MaxFunction {

	private static final long serialVersionUID = 1L;

	private final EditDistanceAlgorithm algorithm;
	private Map<String, Double> cache;
	@Getter
	private final AlgorithmInitializator initializator;
	private final int iterations;
	private GeneticResult result;
	private List<GeneticResult> results;
// Path: edits-core/src/main/java/org/edits/distance/algorithm/EditDistanceAlgorithm.java
// @Data
// @Log4j
// public abstract class EditDistanceAlgorithm implements Serializable, Cloneable {
// 
// 	private static final long serialVersionUID = 1L;
// 	private Matcher matcher;
// 	private boolean normalize;
// 
// 	public EditDistanceAlgorithm() {
// 		normalize = true;
// 		matcher = new DefaultMatcher();
// 	}
// 
// 	@Override
// 	public abstract EditDistanceAlgorithm clone();
// 
// 	public EditDistanceAlgorithm defaultCopy() {
// 		EditDistanceAlgorithm a = instance(this.getClass().getName());
// 		a.setMatcher(getMatcher().copy());
// 		a.setNormalize(normalize);
// 		return a;
// 	}
// 
// 	public double distance(AnnotatedText t, AnnotatedText h, String pairID) {
// 		List<Annotation> w1 = t.getAnnotation();
// 		List<Annotation> w2 = h.getAnnotation();
// 		return distance(w1, w2, t, h, pairID);
// 	}
// 
// 	public abstract double distance(List<Annotation> ta, List<Annotation> ha, AnnotatedText t, AnnotatedText h,
// 			String pairID);
// 
// 	public double init(double dist, double norm) {
// 		if (!normalize)
// 			return dist;
// 		return dist / norm;
// 	}
// 
// 	public EditDistanceAlgorithm instance(String name) {
// 		try {
// 			return (EditDistanceAlgorithm) this.getClass().getClassLoader().loadClass(this.getClass().getName())
// 					.newInstance();
// 		} catch (Exception e) {
// 			log.debug(e);
// 			throw new RuntimeException("Could not load algorithm " + name);
// 		}
// 	}
// }
// 
// Path: edits-core/src/main/java/org/edits/engines/thread/EditsThread.java
// @Log4j
// public abstract class EditsThread<E> {
// 
// 	private boolean finnished = false;
// 	private Iterator<E> iterator;
// 	@Getter
// 	@Setter
// 	private int threads;
// 	private int workers = 0;
// 
// 	public EditsThread() {
// 		Runtime runtime = Runtime.getRuntime();
// 		threads = runtime.availableProcessors();
// 		if (threads > 24)
// 			threads = 24;
// 	}
// 
// 	public EditsThread(int threads_) {
// 		threads = threads_;
// 	}
// 
// 	public synchronized void finnished() {
// 		workers--;
// 		if (workers == 0) {
// 			finnished = true;
// 		}
// 	}
// 
// 	public synchronized void increment() {
// 		workers++;
// 	}
// 
// 	/**
// 	 * @return
// 	 * @throws Exception
// 	 */
// 	public synchronized E next() throws Exception {
// 
// 		if (iterator != null && iterator.hasNext())
// 			return iterator.next();
// 		return null;
// 	}
// 
// 	public abstract void process(E object) throws Exception;
// 
// 	public void start(Iterator<E> iterator_) {
// 		iterator = iterator_;
// 		log.debug("Started with " + threads + " threads");
// 		for (int i = 0; i < threads; i++)
// 			new Worker<E>(this).start();
// 		finnished = false;
// 		try {
// 			while (finnished == false)
// 				Thread.sleep(1000);
// 		} catch (InterruptedException e) {
// 		}
// 		iterator = null;
// 	}
// 
// }
// 
// Path: edits-core/src/main/java/org/edits/etaf/AnnotatedEntailmentPair.java
// @Data
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "AnnotatedEntailmentPair", propOrder = { "t", "h" })
// public class AnnotatedEntailmentPair {
// 
// 	public static AnnotatedEntailmentPair create(String t2, String h2, EditsTextAnnotator annotator) throws Exception {
// 		AnnotatedEntailmentPair px = new AnnotatedEntailmentPair();
// 		AnnotatedText at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(t2));
// 		px.getT().add(at);
// 		at = new AnnotatedText();
// 		at.getAnnotation().addAll(annotator.annotate(h2));
// 		px.getH().add(at);
// 		return px;
// 	}
// 
// 	@XmlTransient
// 	private Map<String, String> attributes;
// 	@XmlAttribute
// 	protected String entailment;
// 	@XmlElement
// 	protected List<AnnotatedText> h;
// 	@XmlAttribute
// 	protected String id;
// 
// 	@XmlTransient
// 	private int order;
// 
// 	@XmlElement
// 	protected List<AnnotatedText> t;
// 
// 	@XmlAttribute
// 	protected String task;
// 
// 	public AnnotatedEntailmentPair() {
// 		t = Lists.newArrayList();
// 		h = Lists.newArrayList();
// 		attributes = Maps.newHashMap();
// 	}
// 
// }


// Path: edits-genetic/src/main/java/org/edits/genetic/OptimizeDistance.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.extern.log4j.Log4j;
import org.edits.distance.algorithm.EditDistanceAlgorithm;
import org.edits.engines.thread.EditsThread;
import org.edits.etaf.AnnotatedEntailmentPair;
import org.jgap.Chromosome;
import org.jgap.Configuration;
import org.jgap.Genotype;
import org.jgap.IChromosome;
import org.jgap.impl.BooleanGene;
import org.jgap.impl.DefaultConfiguration;
import org.jgap.impl.DoubleGene;
import org.jgap.impl.job.MaxFunction;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.AtomicDouble;

package org.edits.genetic;





@Log4j
public class OptimizeDistance extends MaxFunction {

	private static final long serialVersionUID = 1L;

	private final EditDistanceAlgorithm algorithm;
	private Map<String, Double> cache;
	@Getter
	private final AlgorithmInitializator initializator;
	private final int iterations;
	private GeneticResult result;
	private List<GeneticResult> results;
	private final List<AnnotatedEntailmentPair> training;