#!/usr/bin/env python import os, string, re, sys # data handling package from data import * from utils import count_elements # methods with clustering functions from local_search import local_search # VNS functions from perturbations import split from perturbations import melt from heuristic import VNS from stats import * # variables definitions K=10 # number of clusters method=1 #used method index=0 #index of the dependant variable nIter=1 #number of replication d = sys.argv[1:] if len(d) > 0: K = int(d[0]) if len(d) > 1: method = int(d[1]) if len(d) > 2: nIter = int(d[2]) kMax=2*K if len(d) > 3: kMax = int(d[3]) print "Parameters:" print "Numbers of Clusters: ", K print "Perturbations method: ", method print "Number of replications: ", nIter print "Max magnitude of perturbations", kMax print "open_data..." d_temp = load("housing.data", K) listError=[] for i in range(nIter): print "-------- VNS %i ------------" % i try: d = {} d = build_structure(d_temp, K) error = VNS(d,index,method,kMax) listError.append(error) print "---->Structure of Clusters" for k in range(K): print " Cluster %i === %i" % (k, len(d[k])) print "Error = %i" % error except: print "An error appear" moyenne= mean(listError) #for i in listError: # moyenne+=i #moyenne = moyenne / len(listError) #path="/home/etud/lequy/Projet3A/" path = "./res/" filename= path + "result_K" + str(K) + "_M" + str(method) + ".txt" io = open(filename, "w") for i in listError: io.write(str(i)+"\n") print moyenne print listError