private static HashMap<Integer, Integer> parseBranches(final String branches) throws Exception {
		
		final HashMap<Integer, Integer> ans = new HashMap<Integer, Integer>();
		
		if (branches.trim().isEmpty())
			return ans;
		
		if (!branches.contains(")")) {
			final String[] csv = branches.split(",");

			for (int i = 0; i < csv.length; i++) {
				final int bv = Integer.parseInt(csv[i].trim());
				if (!(bv == 0 || bv == 1))
					throw new Exception("Branch values must be either 0 or 1 for each measurement!");
				ans.put(i, bv);
			}
		} else {
			
			final String[] scsv = branches.split(";");

			for (String m : scsv) {
				m = Tools.trimAndCheckBrackets(m);

				final String[] csv = m.split(",");
				final int qubitId = Integer.parseInt(csv[0].trim());
				final int bv = Integer.parseInt(csv[1].trim());
				if (!(bv == 0 || bv == 1))
					throw new Exception("Branch values must be either 0 or 1 for each measurement!");
				if (ans.containsKey(qubitId))
					throw new Exception("B value of qubit "+qubitId+" already specified!");
				ans.put(qubitId, bv);
			}
		}
		
		return ans;
	}