
de.citec.tcs.alignment.ParallelProcessingEngine Maven / Gradle / Ivy
/*
* TCS Alignment Toolbox Version 3
*
* Copyright (C) 2016
* Benjamin Paaßen
* 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 lombok.NonNull;
import java.util.List;
import java.util.concurrent.Callable;
import lombok.Getter;
/**
* This allows parallel processing of alignment calculations. Given two lists of sequences x_1, ...,
* x_M and y_1, ... y_N this calculates the matrix D = (d(x_i, y_j)) of all pairwise distances.
*
* @param the class of elements in the left input sequences.
* @param the class of elements in the right input sequences.
* @param The result type of the alignment algorithm.
*
* @author Benjamin Paassen - [email protected]
*/
public class ParallelProcessingEngine extends MatrixEngine {
/**
* The AlignmentAlgorithm used for pairwise distance computations.
*
* @return The AlignmentAlgorithm used for pairwise distance computations.
*/
@Getter
@NonNull
private final AlignmentAlgorithm algorithm;
/**
* The list of sequences used as left-hand inputs for the AlignmentAlgorithm.
*
* @return The list of sequences used as left-hand inputs for the AlignmentAlgorithm.
*/
@Getter
@NonNull
private final List extends List> leftSequences;
/**
* The list of sequences used as right-hand inputs for the AlignmentAlgorithm.
*
* @return The list of sequences used as right-hand inputs for the AlignmentAlgorithm.
*/
@Getter
@NonNull
private final List extends List> rightSequences;
/**
* This sets up a ParallelProcessingEngine for the given AlignmentAlgorithm
* and the given Sequences. Given two lists of sequences x_1, ...,
* x_M and y_1, ... y_N this calculates the matrix D = (d(x_i, y_j)) of all pairwise distances.
*
* @param algorithm an AlignmentAlgorithm of your choice.
* @param leftSequences a list of sequences as left input for the given AlignmentAlgorithm.
* @param rightSequences a list of sequences as right input for the given AlignmentAlgorithm.
*/
public ParallelProcessingEngine(@NonNull AlignmentAlgorithm algorithm,
@NonNull List extends List> leftSequences, @NonNull List extends List> rightSequences) {
super(leftSequences.size(), rightSequences.size(), algorithm.getResultClass());
this.algorithm = algorithm;
this.leftSequences = leftSequences;
this.rightSequences = rightSequences;
}
@Override
public Callable createCallable(MatrixCoordinate ident) {
return new AlignmentCallable(ident.i, ident.j);
}
private class AlignmentCallable implements Callable {
private final int leftIdx;
private final int rightIdx;
public AlignmentCallable(int leftIdx, int rightIdx) {
this.leftIdx = leftIdx;
this.rightIdx = rightIdx;
}
@Override
public R call() throws Exception {
return algorithm.calculateAlignment(leftSequences.get(leftIdx), rightSequences.get(rightIdx));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy