de.citec.tcs.alignment.AbstractParallelDerivativeEngine 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.parallel.MatrixEngine;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
/**
*
* @author Benjamin Paassen - bpaassen(at)techfak.uni-bielefeld.de
* @param The result class
*/
public abstract class AbstractParallelDerivativeEngine extends MatrixEngine {
private final HashMap algorithms;
public AbstractParallelDerivativeEngine(
Map derivableMatrixEntries, int M, int N, Class resultClass) {
super(M, N, resultClass);
this.algorithms = new HashMap<>(derivableMatrixEntries);
}
public AbstractParallelDerivativeEngine(AlignmentDerivativeAlgorithm[][] derivableMatrixEntries, Class resultClass) {
super(derivableMatrixEntries.length,
MatrixEngine.extractNumberOfColumns(derivableMatrixEntries),
resultClass);
this.algorithms = new HashMap<>();
for (int i = 0; i < getM(); i++) {
if (derivableMatrixEntries[i] == null) {
continue;
}
if (derivableMatrixEntries[i].length != getN()) {
throw new IllegalArgumentException("The number of columns in the input matrix is inconsistent!");
}
for (int j = 0; j < getN(); j++) {
if (derivableMatrixEntries[i][j] == null) {
continue;
}
this.algorithms.put(new MatrixCoordinate(i, j), derivableMatrixEntries[i][j]);
}
}
}
/**
* {@inheritDoc }
*/
@Override
public Callable createCallable(MatrixCoordinate ident) {
final AlignmentDerivativeAlgorithm algo = algorithms.get(ident);
if (algo == null) {
throw new IllegalArgumentException("No derivable matrix entry was given for the matrix coordinate " + ident);
}
return createCallableWithAlgorithm(algo);
}
/**
* Instead of a matrix coordinate identifier, this method should create a
* fitting calculation job for the derivative with the given
* AlignmentDerivativeAlgorithm.
*
* @param algo a AlignmentDerivativeAlgorithm
* @return a fitting calculation job for the derivative with the given
* AlignmentDerivativeAlgorithm
*/
public abstract Callable createCallableWithAlgorithm(AlignmentDerivativeAlgorithm algo);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy