@Override
	public Program generateOffspring(Program firstParent, Program secondParent) throws InvalidProgramException {
		if (!(firstParent instanceof ProgramImpl) || !(secondParent instanceof ProgramImpl)) {
			throw new InvalidProgramException();
		}
		ProgramImpl offspring = ((ProgramImpl) firstParent).clone();
		ProgramImpl parent = ((ProgramImpl) secondParent);
		List<Reaction> offspringReactions = offspring.getReactions();
		List<Reaction> parentReactions = parent.getReactions();
		Random randomGenerator = new Random();
		Reaction selectedReaction = null;
		Reaction simmilarReaction = null;
		int attempts = 0;
		do {
			selectedReaction = offspringReactions.get(randomGenerator.nextInt(offspringReactions.size()));
			simmilarReaction = getSimmilarReaction(parentReactions, selectedReaction);
			attempts++;
		} while (simmilarReaction == null && attempts < MAX_NUMBER_OF_TRIES);
		if (simmilarReaction != null) {
			selectedReaction.changePattern(simmilarReaction.getPattern());
		}
		return offspring;
	}