package org.spbu.bdd.samples.assign;

import java.util.HashSet;
import java.util.Set;

public class AssignBasic {
	Timetable timetable;
	Set<int[]> solutions;
	
	public Set<int[]> solve(Timetable t) {
		timetable = t;
		
		solutions = new HashSet<int[]>();
		int[] solve = new int[timetable.getSize()];
		
		inner(0, solve);
		return solutions;
	}
	
	private boolean gotNext(Integer resNum, int cnum, int[] solve) {
		for (int i = 0; i < cnum; i++) {
			if (resNum == solve[i])
				return false;
		}
		return true;
	}

	public void inner(int cnum, int[] solve) {
		if (cnum == timetable.getSize()) {
			solutions.add(solve);
			return;
		}
		for (Integer resNum : timetable.getConsumerResources(cnum)) {
			if (!gotNext(resNum, cnum, solve))
				continue;

			int[] nsolve = solve.clone();
			nsolve[cnum] = resNum;
			inner(cnum + 1, nsolve);
		}
	}
}
