// Path: src/de/uni_koblenz/west/splendid/helpers/FilterConditionCollector.java
// public class FilterConditionCollector extends QueryModelVisitorBase<RuntimeException> {
// 
// 	public static List<ValueExpr> process(QueryModelNode node) {
// 		FilterConditionCollector collector = new FilterConditionCollector();
// 		node.visit(collector);
// 		return collector.conditions;
// 	}
// 
// 	private List<ValueExpr> conditions = new ArrayList<ValueExpr>();
// 
// 	@Override
// 	public void meet(Filter node)
// 	{
// 		node.getArg().visit(this);
// 		conditions.add(node.getCondition());
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/helpers/Format.java
// public class Format {
// 
// 	private static final StringBuffer b = new StringBuffer();
// 	private static final Formatter f = new Formatter(b, Locale.US);
// 
// 	public static synchronized String d(double value, int length) {
// 		String style = "%." + length + "f";
// 		b.setLength(0);
// 		return f.format(style, value).toString();
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/model/BindJoin.java
// public class BindJoin extends Join {
// 	
// 	public BindJoin(TupleExpr leftArg, TupleExpr rightArg) {
// 		super(leftArg, rightArg);
// 	}
// 	
// 	@Override
// 	public boolean equals(Object other) {
// 		return other instanceof BindJoin && super.equals(other);
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		return super.hashCode() ^ "BindJoin".hashCode();
// 	}
// 
// 	@Override
// 	public BindJoin clone() {
// 		return (BindJoin)super.clone();
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/model/HashJoin.java
// public class HashJoin extends Join {
// 	
// 	public HashJoin(TupleExpr leftArg, TupleExpr rightArg) {
// 		super(leftArg, rightArg);
// 	}
// 	
// 	@Override
// 	public boolean equals(Object other) {
// 		return other instanceof HashJoin && super.equals(other);
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		return super.hashCode() ^ "HashJoin".hashCode();
// 	}
// 
// 	@Override
// 	public HashJoin clone() {
// 		return (HashJoin)super.clone();
// 	}
// 
// }


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openrdf.query.algebra.Filter;
import org.openrdf.query.algebra.Join;
import org.openrdf.query.algebra.StatementPattern;
import org.openrdf.query.algebra.TupleExpr;
import org.openrdf.query.algebra.ValueExpr;
import org.openrdf.query.algebra.helpers.StatementPatternCollector;
import org.openrdf.query.algebra.helpers.VarNameCollector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.uni_koblenz.west.splendid.helpers.FilterConditionCollector;
import de.uni_koblenz.west.splendid.helpers.Format;
import de.uni_koblenz.west.splendid.model.BindJoin;
import de.uni_koblenz.west.splendid.model.HashJoin;
/*
 * This file is part of RDF Federator.
 * Copyright 2011 Olaf Goerlitz
 * 
 * RDF Federator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * RDF Federator 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RDF Federator.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * RDF Federator uses libraries from the OpenRDF Sesame Project licensed 
 * under the Aduna BSD-style license. 
 */
package de.uni_koblenz.west.splendid.optimizer;




/**
 * @author Olaf Goerlitz
 */
public class DynamicProgrammingOptimizer extends AbstractFederationOptimizer {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(DynamicProgrammingOptimizer.class);
	
	private boolean bindJoin;
	private boolean hashJoin;
			
	public DynamicProgrammingOptimizer(boolean hashJoin, boolean bindJoin) {
		if (hashJoin == false && bindJoin == false)
			throw new IllegalArgumentException("cannot create joins: all physical join types are disabled");
		this.bindJoin = bindJoin;
		this.hashJoin = hashJoin;
	}

	@Override
	public TupleExpr optimizeBGP(TupleExpr bgp) {
		
		long time = System.currentTimeMillis();

		PlanCollection optPlans = new PlanCollection();
// Path: src/de/uni_koblenz/west/splendid/helpers/FilterConditionCollector.java
// public class FilterConditionCollector extends QueryModelVisitorBase<RuntimeException> {
// 
// 	public static List<ValueExpr> process(QueryModelNode node) {
// 		FilterConditionCollector collector = new FilterConditionCollector();
// 		node.visit(collector);
// 		return collector.conditions;
// 	}
// 
// 	private List<ValueExpr> conditions = new ArrayList<ValueExpr>();
// 
// 	@Override
// 	public void meet(Filter node)
// 	{
// 		node.getArg().visit(this);
// 		conditions.add(node.getCondition());
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/helpers/Format.java
// public class Format {
// 
// 	private static final StringBuffer b = new StringBuffer();
// 	private static final Formatter f = new Formatter(b, Locale.US);
// 
// 	public static synchronized String d(double value, int length) {
// 		String style = "%." + length + "f";
// 		b.setLength(0);
// 		return f.format(style, value).toString();
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/model/BindJoin.java
// public class BindJoin extends Join {
// 	
// 	public BindJoin(TupleExpr leftArg, TupleExpr rightArg) {
// 		super(leftArg, rightArg);
// 	}
// 	
// 	@Override
// 	public boolean equals(Object other) {
// 		return other instanceof BindJoin && super.equals(other);
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		return super.hashCode() ^ "BindJoin".hashCode();
// 	}
// 
// 	@Override
// 	public BindJoin clone() {
// 		return (BindJoin)super.clone();
// 	}
// 
// }
// 
// Path: src/de/uni_koblenz/west/splendid/model/HashJoin.java
// public class HashJoin extends Join {
// 	
// 	public HashJoin(TupleExpr leftArg, TupleExpr rightArg) {
// 		super(leftArg, rightArg);
// 	}
// 	
// 	@Override
// 	public boolean equals(Object other) {
// 		return other instanceof HashJoin && super.equals(other);
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		return super.hashCode() ^ "HashJoin".hashCode();
// 	}
// 
// 	@Override
// 	public HashJoin clone() {
// 		return (HashJoin)super.clone();
// 	}
// 
// }


// Path: src/de/uni_koblenz/west/splendid/optimizer/DynamicProgrammingOptimizer.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openrdf.query.algebra.Filter;
import org.openrdf.query.algebra.Join;
import org.openrdf.query.algebra.StatementPattern;
import org.openrdf.query.algebra.TupleExpr;
import org.openrdf.query.algebra.ValueExpr;
import org.openrdf.query.algebra.helpers.StatementPatternCollector;
import org.openrdf.query.algebra.helpers.VarNameCollector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.uni_koblenz.west.splendid.helpers.FilterConditionCollector;
import de.uni_koblenz.west.splendid.helpers.Format;
import de.uni_koblenz.west.splendid.model.BindJoin;
import de.uni_koblenz.west.splendid.model.HashJoin;

/*
 * This file is part of RDF Federator.
 * Copyright 2011 Olaf Goerlitz
 * 
 * RDF Federator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * RDF Federator 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RDF Federator.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * RDF Federator uses libraries from the OpenRDF Sesame Project licensed 
 * under the Aduna BSD-style license. 
 */
package de.uni_koblenz.west.splendid.optimizer;




/**
 * @author Olaf Goerlitz
 */
public class DynamicProgrammingOptimizer extends AbstractFederationOptimizer {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(DynamicProgrammingOptimizer.class);
	
	private boolean bindJoin;
	private boolean hashJoin;
			
	public DynamicProgrammingOptimizer(boolean hashJoin, boolean bindJoin) {
		if (hashJoin == false && bindJoin == false)
			throw new IllegalArgumentException("cannot create joins: all physical join types are disabled");
		this.bindJoin = bindJoin;
		this.hashJoin = hashJoin;
	}

	@Override
	public TupleExpr optimizeBGP(TupleExpr bgp) {
		
		long time = System.currentTimeMillis();

		PlanCollection optPlans = new PlanCollection();
		List<ValueExpr> conditions = FilterConditionCollector.process(bgp);