예제 #1
0
    def test_first_is_zeros(self):
        b = Bruteforce(digits=3, bound=2)

        expected = [0, 0, 0]
        actual = b.first()

        self.assertListEqual(expected, actual)
예제 #2
0
    def test_range(self):
        b = Bruteforce(digits=2, bound=3)

        expected = [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
        actual = b.range()

        self.assertListEqual(expected, actual)
예제 #3
0
    def test_increment_with_carry(self):
        b = Bruteforce(digits=4, bound=4)

        expected = [0, 0, 1 ,0]
        actual = b.increment([0,0,0,3])

        self.assertListEqual(expected, actual)
예제 #4
0
    def test_increment_zero(self):
        b = Bruteforce(digits=4, bound=4)

        expected = [0, 0, 0 ,1]
        actual = b.increment([0,0,0,0])

        self.assertListEqual(expected, actual)
예제 #5
0
bf = Bruteforce(point_names, tbl)
bf.start('0')

#sys.exit(0)

point_names, tbl = console.from_file(testpath + 'test1.input', distance.input_names_and_distance)
resolve_by_littl(point_names, tbl)
assert(console.compare_files('littl.output', testpath + 'littl/test1.output'))

bf = Bruteforce(point_names, tbl)
bf.start('1')

#sys.exit(0)

point_names, tbl = console.from_file(testpath + 'test3zero.input', distance.input_names_and_distance)
resolve_by_littl(point_names, tbl)
assert(console.compare_files('littl.output', testpath + 'littl/test3zero.output'))

point_names, tbl = console.from_file(testpath + 'littl/big20.output', distance.input_names_and_distance)
resolve_by_littl(point_names, tbl)
assert(console.compare_files('littl.output', testpath + 'littl/big20.output'))
"""

point_names, tbl = distance.random_distance(11)
resolve_by_littl(point_names, tbl)

bf = Bruteforce(point_names, tbl)
bf.start('A')

#resolve_by_littl(*distance.random_distance(8))
예제 #6
0
파일: main.py 프로젝트: devw4lL/algoinvest
files = f'Choisir un set de donnees:\n' \
        f'--> 1 data_20.csv (set de 20 action).\n' \
        f'--> 2 dataset1.csv (set de 1000 actions Sienna).\n' \
        f'--> 3 dataset2.csv (set de 1000 actions Sienna).\n'

if __name__ == "__main__":
    running = True
    print(welcome)
    while running:
        choice = check_menu(input('Entrer le numero du menu: '))
        solutions = Solutions()
        if choice == 1:
            print(files)
            file = check_files(
                input('Entrer le numero du fichier a analyser: \n'), files)
            brute_force = Bruteforce(solutions)
            brute_force.knapsack_bruteforce([
                Action(action).convert_to_cents()
                for action in load_csv(PATH, file)
            ], MAX_COST)
            solutions.add_profit()
            solutions.sort_by_best_profit()
            print(solutions)
        elif choice == 2:
            print(files)
            file = check_files(
                input('Entrer le numero du fichier a analyser: \n'), files)
            kp_dynamic = KpDynamic(solutions)
            kp_dynamic.knapsack([
                Action(action).convert_to_cents()
                for action in load_csv(PATH, file)
예제 #7
0
from bisect import Bisect
from secant import Secant
from bruteforce import Bruteforce
from newton import Newton


def f(x):
    return x**2 + 4 * np.sin(x)


left = int(input('Enter left border: '))
right = int(input('Enter right border: '))
n = int(input('Enter number of points: '))

bf = Bruteforce(left, right, n, f)
bf.FirstStep()
bf.plots()

s1 = Secant.find(f, a=-2, b=-1)
s2 = Secant.find(f, a=-1, b=1)
b1 = Bisect.find(f, a=-2, b=-1)
b2 = Bisect.find(f, a=-1, b=1)

print("\nSecant: {} {}".format(s1, s2))
print("Bisect: {} {}".format(b1, b2))


def dfunc(x):
    return 2 * x + 4 * cos(x)