#
# Copyright (c) 2011 Laboratoire d'Informatique de Paris Nord (LIPN)
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

EXEC = machineReassignment  
all: $(EXEC)

CC = gcc
CFLAGS = -Wall -Wextra -Wconversion  -Wno-unused  -O3 #-DTRACE_ALGOS #-DDEBUGSTATS# -DDEBUG #-DDEBUGSTATS #-O3 #-DDEBUGSTATS  #-DDEBUGIO

LD = $(CC)
# LDOPT = -g -pthread
LDOPT = $(CFLAGS) -pthread
LDPATHS = 
# LIBS = -lefence
LIBS = -lm
OBJECTS = fmr.o fmr_io.o fmr_core.o fmr_cost.o fmr_tools.o fmr_mem.o fmr_ens.o fmr_heap.o\
		fmr_constraints.o fmr_psmvt.o fmr_glouton.o\
		fmr_exploShift.o fmr_exploSwap.o fmr_exploEjection.o fmr_exploRandSwap.o\
		fmr_servicegraph.o fmr_composanteConnexe.o fmr_recuit.o fmr_recuit_b.o fmr_recuit_c.o fmr_tirage.o fmr_stats.o\
		fmr_threads.o fmr_vns.o fmr_profondeur.o fmr_relax.o

SOURCES = $(subst .o,.c,$(OBJECTS)) $(subst .o,.h,$(OBJECTS))
TESTSA1 = testa1_1 testa1_2 testa1_3 testa1_4 testa1_5
TESTSA2 = testa2_1 testa2_2 testa2_3 testa2_4 testa2_5
TESTB = testb_1 testb_2 testb_3 testb_4 testb_5 testb_6 testb_7 testb_8 testb_9 testb_10

ALGOSA = -A GSCV
ALGOSB = -B BCN


TIMEOUT = -t 300

# si pas d'option SEED: choix de graine aleatoire
SEED = -s 16

STRUCTRESULTAT = 

$(OBJECTS) : fmr.h


$(EXEC): $(OBJECTS)
	$(LD) $(LDOPT) -o $@ $(OBJECTS) $(LDPATHS) $(LIBS)

diffSolution: diffSolution.o fmr_io.o fmr_tools.o fmr_mem.o fmr_cost.o
	$(CC) $(LDOPT) $(CFLAGS) -o $@ $^

aggregeInstances: aggregeInstances.o fmr_io2.o fmr_mem2.o fmr_tools.o
	$(CC) $(LDOPT) $(CFLAGS) -o $@ $^

%.o: %.c %.h
	$(CC) $(CFLAGS) -o $@ -c $<

clean:
	@rm -f $(EXEC) $(OBJECTS)

test:
	make testa1_1
tests:
	make $(TESTSA1)
	make $(TESTSA2)
	make $(TESTB)
testB:
	make $(TESTB)

# % peut remplacer a1_1  a1_5 ou a2_1  a2_5

test%: $(EXEC)
	@rm -f resultat.out
	 /usr/bin/time -f 'mem utilisee:%M ko, fautes de page:%F, temps:%E' ./$(EXEC) -p ../donnees/model_$*.txt  -i ../donnees/assignment_$*.txt -o "resultat_$(ALGOSA)_$(ALGOSB)_$*.txt" \
		$(SEED) $(STRUCTRESULTAT) $(ALGOSA) $(ALGOSB) $(TIMEOUT)
	@sh -c 'if [ ! -f ../checker/solution_checker ] ; then cd ../checker ; make ; cd - ; fi'
	../checker/solution_checker ../donnees/model_$*.txt ../donnees/assignment_$*.txt ../donnees/assignment_$*.txt
	../checker/solution_checker ../donnees/model_$*.txt ../donnees/assignment_$*.txt "resultat_$(ALGOSA)_$(ALGOSB)_$*.txt"

debug: $(EXEC)
	echo "Arguments: -p ../donnees/model_a1_1.txt  -i ../donnees/assignment_a1_1.txt -o resultat.out $(SEED) -A $(ALGOSA) -B $(ALGOSB)"
	gdb fmr

archive: $(EXEC)
	make clean
	make $(EXEC)
	tar czf s26.tgz $(EXEC) Makefile $(SOURCES) README

.PHONY: test debug
