Exemple #1
0
def make_lists_and_plot(xarr, yarr, name, plot_energies: bool, savetxt: bool,
                        dest: str):
    c = Cycle(xarr, yarr)
    if not c.analyse_cycle():
        return
    number_of_cycles = c.number_of_cycles
    elastic = []
    plastic = []
    friction = []
    plastic_total = []
    x_grid = c.x_grid
    for i in range(number_of_cycles):
        e, p, f, p_t = c.evaluate_cycle(i)
        if p > 20:
            print('Fehler in Berechnung der plastic energy in {}'.format(name),
                  file=sys.stderr)

        elastic.append(e)
        plastic.append(p)
        friction.append(f)
        plastic_total.append(p_t)

    # save data as txt-file
    if savetxt:
        for directory in ['elastic', 'plastic', 'friction', 'plastic_total']:
            if not os.path.exists(os.path.join(dest, directory, '')):
                os.makedirs(os.path.join(dest, directory))
            np.savetxt(
                os.path.join(dest, directory, '') + name + '.txt',
                np.transpose([x_grid, eval(directory)]), '%.2f')
    # plot energies as pdf
    if plot_energies:
        plot(x_grid, elastic, plastic, friction, plastic_total, xarr, yarr,
             name, dest)
Exemple #2
0
 def loadScripts(self, dir):
     import sys
     sys.path.insert(0, "./scripts")
     from Script import Script
     s = Script(self, "test")
     from loading import Loading
     l = Loading(self.segments[0])
     self.scripts.append(l)
     from TheaterChase import TheaterChase
     t = TheaterChase(self.segments[0])
     self.scripts.append(t)
     from rainbow import Rainbow
     r = Rainbow(self.segments[0])
     self.scripts.append(r)
     from LeftToRightRandom import LeftToRightRandom
     lr = LeftToRightRandom(self.segments[0])
     self.scripts.append(lr)
     from RandomLed import RandomLed
     r = RandomLed(self.segments[0])
     self.scripts.append(r)
     from Light import Light
     self.scripts.append(Light(self.segments[0]))
     from Test import Test
     self.scripts.append(Test(self.segments[0]))
     from Cycle import Cycle
     self.scripts.append(Cycle(self.segments[0]))
     from SingleColor import SingleColor
     self.scripts.append(SingleColor(self.segments[0]))
Exemple #3
0
    def run(self):
        # Should we run the scraper? This is controlled in Constants
        if RUN_SCRAPER:
            scrape_stats(WEEK)

        # Is this a testing run or a real run? Testing runs are significantly longer
        if TESTING:
            # Set up the progressbar
            with alive_bar((STEPS * (YEAR + 1 - START_YEAR))) as bar:
                # Set up the output dataframe
                outputs = pd.DataFrame(
                    columns=['iter_year', 'perc_correct', 'dv_value'])

                for iter_d_v in np.linspace(LOW_D_V, HIGH_D_V, STEPS):
                    testing_games = pd.DataFrame()
                    testing_teams = pd.DataFrame()
                    testing_plays = pd.DataFrame()
                    testing_stats = pd.DataFrame()

                    for iter_year in range(START_YEAR, YEAR + 1):
                        self.build_options(iter_d_v)

                        bar()

                        # Run the cycle
                        polling_cycle = Cycle(self.options, iter_year)
                        results = polling_cycle.run()

                        # Append the iterated dependent variable to our data set
                        results.append(iter_d_v)
                        results_series = pd.Series(results,
                                                   index=outputs.columns)
                        outputs = outputs.append(results_series,
                                                 ignore_index=True)

                # Dump the DV outputs to a CSV
                outputs.to_csv('research/D_V.csv')

                # Print out the DV graph
                fig = px.scatter(outputs, x='dv_value', y='perc_correct')
                fig.write_html('research/dv_test.html')
        else:
            with alive_bar(length=(YEAR + 1 - START_YEAR)) as bar:
                for iter_year in range(START_YEAR, YEAR + 1):
                    self.build_options()

                    bar()
                    polling_cycle = Cycle(self.options, iter_year)
                    output = polling_cycle.run()
Exemple #4
0
class methods:
    def __init__(self, fps, clockObject, surface, font, bars, windowsize):
        self.fps = fps
        self.clock = clockObject
        self.surface = surface
        self.font = font
        self.bars = bars
        self.windowsize = windowsize

    def get_array(self, length, mode=0):
        arr = list(range(length))

        if not mode:
            random.shuffle(arr)
        elif mode == 2:
            arr = arr[::-1]
        elif mode == 3:
            for i in range(length - 1):
                if random.randint(0, 10) < 8:
                    tmp = random.randint(4, 15)
                    try:
                        arr[i], arr[i + tmp] = arr[i + tmp], arr[i]
                    except:
                        pass

        return arr

    def setup(self, length, mode=0):
        self.array = self.get_array(length, mode)

        self.display = Display(self.windowsize[0] / length, self.windowsize,
                               self.surface, self.font)
        self.accesses = 0
        self.comparisons = 0

        setattr(self.display, "bars", self.bars)

    bubble = lambda self: Bubble(self.array, self.display, self.clock, self.fps
                                 ).main()
    quicksort = lambda self: Quicksort(self.array, self.display, self.clock,
                                       self.fps).main()
    selection = lambda self: Selection(self.array, self.display, self.clock,
                                       self.fps).main()
    cocktail = lambda self: Cocktail(self.array, self.display, self.clock, self
                                     .fps).main()
    bogo = lambda self: Bogo(self.array, self.display, self.clock, self.fps
                             ).main()
    oddeven = lambda self: Oddeven(self.array, self.display, self.clock, self.
                                   fps).main()
    shell = lambda self: Shell(self.array, self.display, self.clock, self.fps
                               ).main()
    comb = lambda self: Comb(self.array, self.display, self.clock, self.fps
                             ).main()
    insertion = lambda self: Insertion(self.array, self.display, self.clock,
                                       self.fps).main()
    mergetd = lambda self: MergeTD(self.array, self.display, self.clock, self.
                                   fps).main()
    radixlsd = lambda self: RadixLSD(self.array, self.display, self.clock, self
                                     .fps).main()
    counting = lambda self: Counting(self.array, self.display, self.clock, self
                                     .fps).main()
    cycle = lambda self: Cycle(self.array, self.display, self.clock, self.fps
                               ).main()
    heap = lambda self: Heap(self.array, self.display, self.clock, self.fps
                             ).main()
    circle = lambda self: Circle(self.array, self.display, self.clock, self.fps
                                 ).main()
    gnome = lambda self: Gnome(self.array, self.display, self.clock, self.fps
                               ).main()
    binaryinsertion = lambda self: BinaryInsertion(
        self.array, self.display, self.clock, self.fps).main()
    pancake = lambda self: Pancake(self.array, self.display, self.clock, self.
                                   fps).main()
    permutation = lambda self: Permutation(self.array, self.display, self.
                                           clock, self.fps).main()
    strand = lambda self: Strand(self.array, self.display, self.clock, self.fps
                                 ).main()
    bucket = lambda self: Bucket(self.array, self.display, self.clock, self.fps
                                 ).main()
    minmax = lambda self: MinMax(self.array, self.display, self.clock, self.fps
                                 ).main()
    mergebu = lambda self: MergeBU(self.array, self.display, self.clock, self.
                                   fps).main()
    bitonic = lambda self: Bitonic(self.array, self.display, self.clock, self.
                                   fps).main()
    stooge = lambda self: Stooge(self.array, self.display, self.clock, self.fps
                                 ).main()
    smooth = lambda self: Smooth(self.array, self.display, self.clock, self.fps
                                 ).main()
    quick3 = lambda self: Quick3(self.array, self.display, self.clock, self.fps
                                 ).main()
	def _hasCycle(self, G):
		cycle = Cycle(G)
		return cycle.hasCycle()
Exemple #6
0
from Cycle import Cycle

my_cycle = Cycle()

# main input loop
my_cycle.print_options()
user_input = int(input())

while user_input != 0:
    my_cycle.update_cycle(user_input)
    my_cycle.print_new_idea()
    my_cycle.print_options()
    user_input = int(input())
Exemple #7
0
import re
# from Union_find import UnionFind
from Cycle import Cycle
from BFS import BreadFirstSearch
from DFS import DepthFirstSearch
from Graph import Graph
from CC import CC
from TwoColor import TwoColor
if __name__ == '__main__':
    with open('c:\\Users\\wangym20804\\Desktop\\tinyUF.txt') as f:

        n = int(f.readline())
        graph = Graph(n)
        for line in f:
            vw = map(int, re.split(r' *', line))
            graph.add_edge(vw[0], vw[1])
        print(graph)
    bfs = BreadFirstSearch(graph, 0)
    dfs = DepthFirstSearch(graph, 0)
    cc = CC(graph)
    cycle = Cycle(graph)
    two_color = TwoColor(graph)

    print(bfs.path_to(4))
    print(dfs.path_to(4))
    print(cc.count())
    print(cycle.has_cycle())
    print(two_color.is_two_color())
 def _hasCycle(self, G):
     cycle = Cycle(G)
     return cycle.hasCycle()