 LANGUAGE PLPGSQL;
 
 
-CREATE OR REPLACE FUNCTION GENERATE_SEED_EXPERIMENTS(PARAM_EXPERIMENT_GROUP_ID BIGINT) RETURNS VOID
+CREATE OR REPLACE FUNCTION GENERATE_SEED_EXPERIMENTS() RETURNS VOID
 AS
 $$
 DECLARE EXPERIMENTS_TO_CREATE INT;
+DECLARE EXPERIMENT_GROUP_ID BIGINT;
 DECLARE NEWLY_CREATED_EXPERIMENT_ID BIGINT;
 BEGIN
 	SELECT
-		GC.STARTING_POPULATION_SIZE - COUNT(*) INTO EXPERIMENTS_TO_CREATE
+		GC.STARTING_POPULATION_SIZE - COUNT(*),
+		EG.ID
+	INTO 
+		EXPERIMENTS_TO_CREATE,
+		EXPERIMENT_GROUP_ID
 	FROM
 		EXPERIMENT_GROUP EG
 	LEFT JOIN

		GROUP_CONFIG GC
	ON
		GC.ID = EG.GROUP_CONFIG_ID
	WHERE
		EG.ID = PARAM_EXPERIMENT_GROUP_ID
	GROUP BY
		GC.STARTING_POPULATION_SIZE;

--	RAISE NOTICE 'CREATEING % EXPERIMENTS' , EXPERIMENTS_TO_CREATE;

	IF EXPERIMENTS_TO_CREATE > 0 THEN

		INSERT INTO EXPERIMENT ( EXPERIMENT_GROUP_ID)
		VALUES ( PARAM_EXPERIMENT_GROUP_ID )
		RETURNING ID INTO NEWLY_CREATED_EXPERIMENT_ID;
		PERFORM FILL_IN_MISSING_PARAMETERS(NEWLY_CREATED_EXPERIMENT_ID);
		-- SAFE, BUT I/O HEAVY WAY TO GUARANTEE WE DON'T OVERFILL THE STARTING POPULATION FOR THIS EXPERIMENT_GROUP
		PERFORM GENERATE_SEED_EXPERIMENTS(PARAM_EXPERIMENT_GROUP_ID); 
	END IF;
END
$$

(
	'BASIC_DETERMINISTIC', --ID,
	50, --STARTING_POPULATION_SIZE,
	10, --NUMBER_OF_RECENT_CONTENDERS,
	10, --NUMBER_OF_RANDOM_CONTENDERS,
	10, --NUMBER_OF_BEST_CONTENDERS,
	2, --PERFORMANCE_BIAS,
	0, --RESAMPLE_BIAS,
	0 --RESAMPLE_PROBABILITY
),
