Example #1
0
def main(argv):

    POINTS = generate_points(argv[1])
    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])

    if argv[0] == "BF":
        #Exécuter l'algorithme force brute
        time_BF, min_DistanceBF = execute_brute_force(sorted_points_x)
        if '-t' in argv:
            print("Temps : ", time_BF)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceBF)

    elif argv[0] == "DPR":
        #Exécuter l'algorithme Diviser pour régner
        SEUIL_DPR = 3
        time_DPR, min_DistanceDPR = execute_DpR(sorted_points_x,
                                                sorted_points_y, SEUIL_DPR)
        if '-t' in argv:
            print("Temps : ", time_DPR)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceDPR)

    elif argv[0] == "seuil":
        SEUIL_DPR = 4
        time_DPR, min_DistanceDPR = execute_DpR(sorted_points_x,
                                                sorted_points_y, SEUIL_DPR)
        if '-t' in argv:
            print("Temps : ", time_DPR)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceDPR)
Example #2
0
def process_single_file(algo, path, display_time, display_result):
    file_object = open(path, "r")
    values = file_object.readlines()
    n = int(values[0])
    POINTS = []

    for i in range(1,n+1):
        temp = values[i].split(" ")
        POINTS.append((int(temp[0]),int(temp[1])))

    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])

    if algo == "brute":
        # Exécuter l'algorithme force brute     
        time_BF = execute_brute_force(sorted_points_x, display_result)
        if (int(display_time) == 1):
            print("Temps : ", time_BF)
    
    elif algo == "recursif":
        # Exécuter l'algorithme Diviser pour régner
        time_DPR = execute_DpR(sorted_points_x, sorted_points_y, 2, display_result)
        if (int(display_time) == 1):
            print("Temps : ", time_DPR)
    
    elif algo == "seuil":
        # Exécuter l'algorithme Diviser pour régner avec un seuil expérimental
        time_DPR = execute_DpR(sorted_points_x, sorted_points_y, 16, display_result)
        if (display_time == "1"):
            print("Temps : ", time_DPR)
Example #3
0
def main(argv):

    algos = ["brute", "recursif", "seuil"]

    if Path(argv[1]).is_file():
        POINTS = generate_points(argv[1])
    else:
        print(
            "Les paramètres ne sont pas correcte ou vous n'avez pas entré un fichier valide."
        )
        sys.exit()
    if not argv[0].lower() in algos:
        print(
            "Les paramètres ne sont pas correcte Veuillez vous assurer d'avoir entrer l'une des options suivante en respéctant la casse"
        )
        print("brute | recursif | seuil")
        sys.exit()

    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])
    if argv[0].lower() == "brute":
        #Exécuter l'algorithme force brute
        time_BF, min_DistanceBF = execute_brute_force(sorted_points_x)
        if '-t' in argv:
            print("Temps : ", time_BF)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceBF)

    elif argv[0].lower() == "recursif":
        #Exécuter l'algorithme Diviser pour régner avec un seuil élémentaire
        SEUIL_DPR = 3
        time_DPR, min_DistanceDPR = execute_DpR(sorted_points_x,
                                                sorted_points_y, SEUIL_DPR)
        if '-t' in argv:
            print("Temps : ", time_DPR)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceDPR)

    elif argv[0].lower() == "seuil":
        #Exécuter l'algorithme Diviser pour régner avec un seuil déterminé expérimentalement
        SEUIL_seuil = 21
        time_seuil, min_Distanceseuil = execute_DpR(sorted_points_x,
                                                    sorted_points_y,
                                                    SEUIL_seuil)
        if '-t' in argv:
            print("Temps : ", time_seuil)
        if '-p' in argv:
            print("Plus petite distance: ", min_Distanceseuil)
Example #4
0
def main(algo, filepath, marker):
    getcontext().prec = 5000
    POINTS = getPointsfromFile(filepath)
    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])
    
    if algo == "brute":
        # Exécuter l'algorithme force brute
        time_BF, dist_BF, points_BF = execute_brute_force(sorted_points_x)
        if (marker == 'p'):
            print("Minimum distance : ", dist_BF)
        elif (marker == 't'):
            print("Time : ", time_BF)
        else:
            
            print("Time : ", Decimal(time_BF))
            print("Minimum distance : ", dist_BF)
            print("Solution Points: ", points_BF)
    
    elif algo == "recursif":
        # Exécuter l'algorithme Diviser pour régner
        SEUIL_DPR = threshold_Arbitrary
        time_DPR, dist_DPR, points_DPR = execute_DpR(sorted_points_x, sorted_points_y, SEUIL_DPR)
        if (marker == 'p'):
            print("Minimum distance : ", dist_DPR)
        elif (marker == 't'):
            print("Time : ", time_DPR)
        else:
            print("Time : ", time_DPR)
            print("Minimum distance : ", dist_DPR)
            print("Solution Points: ", points_DPR)
        
    elif algo == "seuil":
        # Exécuter l'algorithme Diviser pour régner avec seuil de recursivite experimental
        SEUIL_DPR = threshold_Experimental
        time_DPR, dist_DPR, points_DPR = execute_DpR(sorted_points_x, sorted_points_y, SEUIL_DPR)
        if (marker == 'p'):
            print("Minimum distance : ", dist_DPR)
        elif (marker == 't'):
            print("Time : ", time_DPR)
        else:
            print("Time : ", time_DPR)
            print("Minimum distance : ", dist_DPR)
            print("Solution Points: ", points_DPR)
Example #5
0
def main(algo, nb_points):
    POINTS = generate_points(nb_points)
    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])
    
    if algo == "BF":
        # Exécuter l'algorithme force brute
        time_BF = execute_brute_force(sorted_points_x)
        print("Temps : ", time_BF)
    
    elif algo == "DPR":
        # Exécuter l'algorithme Diviser pour régner
        SEUIL_DPR = 3
        time_DPR = execute_DpR(sorted_points_x, sorted_points_y, SEUIL_DPR)
        print("Temps : ", time_DPR)
Example #6
0
def main(argv):
    
    POINTS = generate_points(argv[1])
    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])
    if argv[0].lower() == "bf":
        #Exécuter l'algorithme force brute
        time_BF, min_DistanceBF = execute_brute_force(sorted_points_x)
        if '-t' in argv:
            print("Temps : ", time_BF)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceBF)
        row=["BF",argv[1],time_BF,min_DistanceBF]
    
    elif argv[0].lower() == "dpr":
        #Exécuter l'algorithme Diviser pour régner
        SEUIL_DPR = 3
        time_DPR, min_DistanceDPR = execute_DpR(sorted_points_x, sorted_points_y, SEUIL_DPR)
        if '-t' in argv:
            print("Temps : ", time_DPR)
        if '-p' in argv:
            print("Plus petite distance: ", min_DistanceDPR)
        row=["DPR",argv[1],time_DPR,min_DistanceDPR]
        
    elif argv[0].lower() == "seuil":
        SEUIL_seuil = 4
        time_seuil, min_Distanceseuil = execute_DpR(sorted_points_x, sorted_points_y, SEUIL_seuil)
        if '-t' in argv:
            print("Temps : ", time_seuil)
        if '-p' in argv:
            print("Plus petite distance: ", min_Distanceseuil)
        row=["seuil",argv[1],time_seuil,min_Distanceseuil]
    
    with open('result.csv', 'a', newline='') as file:
        writer = csv.writer(file, delimiter='|')
        writer.writerow(row)
Example #7
0
def getNminbyTrialAndError(filepath):
    
    POINTS = getPointsfromFile(filepath)
    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])
    
    n_Min = float("inf")
    n_Test = randint(100, 200)
    time_current = float("inf")
    time_previous = float("inf")
    
    while time_current <= time_previous and n_Min > 1:
        n_Min = n_Test
        n_Test = max(int(n_Min / 2), 1)
        time_previous = time_current
        time_current = execute_DpR(sorted_points_x, sorted_points_y, n_Test)[0]
        
    return n_Min
Example #8
0
def main(algo):
    T = []
    for i in N:
        for j in range(1, 11):
            print(i)
            F = open("exemplaire/" + str(i) + "-" + str(j) + ".txt", "r")
            contenu = F.readlines()
            F.close()
            bool = True
            POINTS = []
            for line in contenu:
                if bool:
                    bool = False
                else:
                    k = 0
                    for c in line:
                        if c != " ":
                            k += 1
                        else:
                            POINTS.append(
                                [int(line[0:k]),
                                 int(line[k + 1:len(line)])])
            sorted_points_x = sorted(POINTS, key=lambda x: x[0])
            sorted_points_y = sorted(POINTS, key=lambda x: x[1])
            if ALGO == "BF":
                # Exécuter l'algorithme force brute
                time_BF = execute_brute_force(sorted_points_x)
                T.append(time_BF)
                print("Temps : ", time_BF)

            elif ALGO == "DPR":
                # Exécuter l'algorithme Diviser pour régner
                SEUIL_DPR = int(sys.argv[2])  #Seuil de récursivité
                time_DPR = execute_DpR(sorted_points_x, sorted_points_y,
                                       SEUIL_DPR)
                T.append(time_DPR)
                print("Temps : ", time_DPR)
    T_moy = average(T)
    tracer_puissance(N, T_moy, ALGO)
    tracer_rapport(N, T_moy, ALGO)
    tracer_constantes(N, T_moy, ALGO)
Example #9
0
def main():
    options = getOptions()
    FILE = open(options.path, "r")
    nb_points = FILE.readline()
    POINTS = []
    time = 0
    for x in range(int(nb_points)):
        point1, point2 = FILE.readline().split()
        POINTS.append([int(point1), int(point2)])

    sorted_points_x = sorted(POINTS, key=lambda x: x[0])
    sorted_points_y = sorted(POINTS, key=lambda x: x[1])

    if options.algo == "brute":
        # Exécuter l'algorithme force brute
        time = execute_brute_force(sorted_points_x, options.smallest)

    elif options.algo == "seuil":
        # Exécuter l'algorithme Diviser pour régner
        time = execute_DpR(sorted_points_x, sorted_points_y, 4,
                           options.smallest)

    if options.time:
        print(time)
from utils import threshold_Experimental, threshold_Arbitrary, getPointsfromFile
from DpR import execute_DpR
from brute_force import execute_brute_force
import os

#runs the all three algorithms on all testsets and writes everything into a csv file.

test_directory = "testsets"

with open('data.csv', 'w', newline='') as csvfile:
    filewriter = csv.writer(csvfile, delimiter=',')
    filewriter.writerow([
        'Sample', 'Sample Size', 'Brute Force', 'Divide and Conquer',
        'D&C with Experimental Recursion Threshold'
    ])
    for n in os.listdir(test_directory):
        if str(n) == "10" or str(n) == "100" or str(n) == "50":
            path = os.path.join(test_directory, str(n))
            for file in os.listdir(path):
                print(file)
                POINTS = getPointsfromFile(os.path.join(path, file))
                sorted_points_x = sorted(POINTS, key=lambda x: x[0])
                sorted_points_y = sorted(POINTS, key=lambda x: x[1])

                time_BF = execute_brute_force(sorted_points_x)[0]
                time_DpR = execute_DpR(sorted_points_x, sorted_points_y,
                                       threshold_Arbitrary)[0]
                time_seuil = execute_DpR(sorted_points_x, sorted_points_y,
                                         threshold_Experimental)[0]
                filewriter.writerow([file, n, time_BF, time_DpR, time_seuil])