/**
 * Copyright (c) 2012-2013, Daniele Codecasa <codecasa.job@gmail.com>,
 * Models and Algorithms for Data & Text Mining (MAD) laboratory of
 * Milano-Bicocca University, and all the CTBNCToolkit contributors
 * that will follow.
 * All rights reserved.
 *
 * @author Daniele Codecasa and all the CTBNCToolkit contributors that will follow.
 * @copyright 2012-2013 Daniele Codecasa, MAD laboratory, and all the CTBNCToolkit contributors that will follow
 */
package CTBNCToolkit.clustering;

import java.util.Map;

import CTBNCToolkit.*;


/**
 * @author Daniele Codecasa <codecasa.job@gmail.com>
 *
 * Abstract class that define the generic management
 * of class parameters for clustering algorithms.
 *
 * @param <TimeType> type of the time interval (Integer = discrete time, Double = continuous time)
 * @param <NodeType> type of node in the model
 * @param <Stat> statistics generated by the learning process
 */
public abstract class ClusteringAlgorithm<TimeType extends Number & Comparable<TimeType>, NodeType extends INode> implements IClusteringAlgorithm<TimeType,NodeType>{

	private Map<String, Object> params;
	protected IStopCriterion stopCriterion;
	protected IClassifyAlgorithm<Double, CTDiscreteNode> classificationAlgorithm;
	
	
	@Override
	public void setParameters(Map<String, Object> params) throws IllegalArgumentException {
		
		this.params = params;
	}
	
	
	@Override
	public Object getParameter(String name) throws IllegalArgumentException {
		
		if( this.params == null || this.params.isEmpty())
			throw new IllegalArgumentException("Error: no parameters are defined");
		
		Object value = params.get( name);
		if( value == null)
			throw new IllegalArgumentException("Error: parameter " + name + " not found");
		
		return value;
	}
	


	/* (non-Javadoc)
	 * @see CTBNToolkit.clustering.IClusteringAlgorithm#setClassificationAlgorithm(CTBNToolkit.IClassifyAlgorithm)
	 */
	@Override
	public void setClassificationAlgorithm(
			IClassifyAlgorithm<Double, CTDiscreteNode> clAlg)
			throws IllegalArgumentException {

		if( clAlg == null)
			throw new IllegalArgumentException("Error: null classification algorithm parameter");
		
		this.classificationAlgorithm = clAlg;		
		
	}


	/* (non-Javadoc)
	 * @see CTBNToolkit.clustering.IClusteringAlgorithm#setStopCriterion(CTBNToolkit.clustering.IStopCriterion)
	 */
	@Override
	public void setStopCriterion(IStopCriterion stopCriterion)
			throws IllegalArgumentException {

		if( stopCriterion == null)
			throw new IllegalArgumentException("Error: null stopping criterion");
		
		this.stopCriterion = stopCriterion;		
		
	}

}
