public static void main(String[] args) throws Exception {
		Settings settings = new Settings();
		for (String arg : args) {
			settings.parseSetting(arg);
		}
		
		
		OutputStream outp;
		if (settings.output.length() == 0) {
			outp = System.out;
		} else {
			File file = new File(settings.output);
			File dir = file.getParentFile();
			if (dir != null && !dir.exists())
				dir.mkdirs();
			outp = new FileOutputStream(file);
		}

		/** Create the rubix cube **/
		RubixCube rubixCube = RubixCube.solved();
		if (settings.random >= 0) {
			rubixCube = rubixCube.applyPermutation(RubixCube.getRandomPermutation(settings.random, settings.verbose));
		} else if (settings.moves.length() > 0) {
			rubixCube = rubixCube.applyPermutation(RubixCube.parseMoves(settings.moves.toCharArray()));
			System.err.println(settings.moves);
		} else {
			rubixCube = rubixCube.applyPermutation(RubixCube.getRandomPermutation(15, settings.verbose));
		}
		StateBasedSATProblem<RubixCube> rubixSAT = (StateBasedSATProblem<RubixCube>) Class.forName(settings.encoding).getConstructor().newInstance();
		Expression rubixExpr = rubixSAT.getExpression(rubixCube,settings.max+1);
		System.err.println("Cube expression calculated");
		DIMACSEncoder dimacs = new DIMACSEncoder(rubixExpr);
		dimacs.writeDIMACSTo(outp);
		if(settings.mapping.length()>0) {
			File file = new File(settings.mapping);
			File dir = file.getParentFile();
			if (dir != null && !dir.exists())	
				dir.mkdirs();
			dimacs.writeMappingTo(new PrintStream(file));
		}
	}