All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.citec.tcs.alignment.ParallelDerivativeEngine Maven / Gradle / Ivy

/* 
 * TCS Alignment Toolbox
 * 
 * Copyright (C) 2013-2015
 * Benjamin Paaßen, Georg Zentgraf
 * AG Theoretical Computer Science
 * Centre of Excellence Cognitive Interaction Technology (CITEC)
 * University of Bielefeld
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package de.citec.tcs.alignment;

import de.citec.tcs.alignment.comparators.DerivableComparator;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * This allows parallel processing of derivative calculations.
 *
 * @author Benjamin Paassen - [email protected]
 * @param  the result class of the input comparator.
 */
public class ParallelDerivativeEngine extends AbstractParallelDerivativeEngine {

	private final DerivableComparator comparator;
	private final String keyword;

	public ParallelDerivativeEngine(
		Map derivableMatrixEntries,
		int M, int N, DerivableComparator comparator,
		String keyword) {
		super(derivableMatrixEntries, M, N, comparator.getResultClass());
		this.comparator = comparator;
		this.keyword = keyword;
	}

	public ParallelDerivativeEngine(AlignmentDerivativeAlgorithm[][] derivableMatrixEntries,
		DerivableComparator comparator, String keyword) {
		super(derivableMatrixEntries, comparator.getResultClass());
		this.comparator = comparator;
		this.keyword = keyword;
	}

	/**
	 * {@inheritDoc }
	 */
	@Override
	public Callable createCallableWithAlgorithm(AlignmentDerivativeAlgorithm algo) {
		return new DerivativeCallable(algo);
	}

	private class DerivativeCallable implements Callable {

		private final AlignmentDerivativeAlgorithm algo;

		public DerivativeCallable(AlignmentDerivativeAlgorithm algo) {
			this.algo = algo;
		}

		@Override
		public Y call() throws Exception {
			return algo.calculateParameterDerivative(comparator, keyword);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy