Пример #1
0
class Country():
    #"处理国家"

    def __init__(self, nuclear_lock, ice_lock, creature_lock, oil_lock,
                 coal_lock):
        #初始化国家属性
        self.gold = 15
        self.energy = 0
        self.pollution = 0
        self.locks = {
            "nuclear": int(nuclear_lock),
            "ice": int(ice_lock),
            "creature": int(creature_lock),
            "coal": int(coal_lock),
            "oil": int(oil_lock)
        }
        self.power = Energy()

    def increase(self):
        #每年增加金币
        self.gold += 10

    def input_energy(self):
        #在国家中建造能源
        self.power.build_energy()
        for key, value in self.locks.items():
            try:
                if self.power.built_list[key] > value:
                    self.power.built_list[key] = value
                    print("\n某能源数量超出国家储量,超出上限部分无法建造")
            except KeyError:
                self.power.built_list[key] = 0

    def change_country(self):
        #处理能源带来的各属性变化
        for key, value in self.power.built_list.items():
            if self.power.e_list[key][3] == 1:
                self.gold -= self.power.e_list[key][0] * value
                self.energy += self.power.e_list[key][1] * value
                self.pollution += self.power.e_list[key][2] * value
            else:
                self.energy += self.power.e_list[key][1]
                self.pollution += self.power.e_list[key][2]

    def show(self):
        #展示国家现状
        print("\n能量总产量:" + str(self.energy) + "KJ")
        print("\n金币剩余: " + str(self.gold) + "G")
        print("\n污染情况:" + str(self.pollution) + "平方千米")

    def del_energy(self):
        #删除不可再生能源
        for key in self.power.built_list.keys():
            if self.power.e_list[key][3] == 1:
                self.power.built_list[key] = 0
Пример #2
0
 def __init__(self, nuclear_lock, ice_lock, creature_lock, oil_lock,
              coal_lock):
     #初始化国家属性
     self.gold = 15
     self.energy = 0
     self.pollution = 0
     self.locks = {
         "nuclear": int(nuclear_lock),
         "ice": int(ice_lock),
         "creature": int(creature_lock),
         "coal": int(coal_lock),
         "oil": int(oil_lock)
     }
     self.power = Energy()
Пример #3
0
    def __init__(self):
        self.__version__ = '3.1.3'

        logger_format = '%(asctime)s %(message)s'
        logging.basicConfig(format=logger_format, level=logging.INFO,
                            datefmt="%H:%M:%S", filename='./logfile.log', filemode='w')
        logging.getLogger().addHandler(SysLogHandler(facility=SysLogHandler.LOG_DAEMON, address='/dev/log'))

        self._SIGKILL = False
        self.logging = logging
        self.config = DB('./config.json')

        self.network = Network(self)
        self.display = DisplayContent()
        self.detector = Detector()
        self.ultrasound = Ultrasound(self)
        self.temp = Temp()
        self.server = SimpleWebSocketServer('', 8069, WebSocketServer, self)
        self.cook = Cook(self)
        self.energy = Energy(self)
        self.history = History(self)
        self.audio = Audio(self)
        self.users = Users(self)
        self.automations = Automations(self)

        signal.signal(signal.SIGTERM, self.sig_handler)
        signal.signal(signal.SIGINT, self.sig_handler)

        self.log("Boot: v" + self.__version__)
Пример #4
0
    def __init__(self, l=100, b=100, *args, **kwargs):
        self.l = l  # length of the yard
        self.b = b  # breadth of the yard

        self.nodes = []

        # initialize all values for energy calculations
        self.energy = Energy(kwargs)
        self.packet = Packet()

        self.grid_size = kwargs.get('grid_size', 30)

        cols = self.l / self.grid_size + 1
        rows = self.b / self.grid_size + 1
        self.grid = [[Grid(row, col) for col in range(cols)]
                     for row in range(rows)]  #[0]energy, [1]id

        # 1st node with id = 0 is used as sink, initially placed at center
        sink_x = self.l / 2
        sink_y = self.b / 2
        sink_cell = self.grid[sink_x / self.grid_size][sink_y / self.grid_size]
        self.sink = Node(sink_x, sink_y, self.energy.init, sink_cell)
epsilon=0.01
radial_func=RadialFuncInBall()
center=None


X,Y = np.meshgrid(np.linspace(0,4,nb_players_x),
                  np.linspace(0,4,nb_players_y))
positions_init = np.zeros((nb_players,2))
positions_init[:,0] = X.flatten()
positions_init[:,1] = Y.flatten() 

situation_init=Situation_Init(positions=positions_init, mass=mass)
initial_guess=Trajectories(situation_init=situation_init)


energy=Energy(domain=domain, radial_func=RadialFuncInBall(), epsilon=epsilon, time=time, lagrangian=lambda x:3*np.array([np.sum(x**2)/2,x[0],x[1]]), potential_t=potential_circ, potential_fin=potential_infinity)
optimal_trajectories=energy.minimize(initial_guess=initial_guess, center=center, nb_steps=2**nb_double, steps_global= 2**nb_double, mode='double_middle', nb_procs=30, error=1e-8)


root="Trajectories_convex"
optimal_trajectories.display_trajectories(root=root, domain=domain, radial_func=radial_func)
print("results stored in ",root)


import matplotlib.pyplot as plt
positions = np.load(root + "/alltrajectories.npy")

ee = .01

def show_contour(ax):
    ax.plot([-1,10,10,-1,-1],
Пример #6
0
    config.set_default("led_invert", False)                     # True to invert the signal (when using NPN transistor level shift)
    config.set_default("display_file", "display.json")          # File where display string->led convertion is saved
    config.load()
    config.save()
    config.auto_save = True

    # set runtime config
    config.set_option("display_active", True)                   # If display should be activated (only leds, display still work)

    # set constant options
    config.set_option("led_count", config.get_option("display_height") * config.get_option("display_width"))    # set led count
    config.add_not_saves(["led_count"])

    # Init power
    log.info("Init power")
    power = Energy(config.get_option("power_switch_pin"), config.get_option("power_switch_invert"))

    log.info("Load display file: " + str(config.get_option("display_file")))
    if not os.path.isfile(config.get_option("display_file")):
        log.log_error("Could not find " + str(config.get_option("display_file")))
        exit(1)

    #with open("display.json") as data_file:
    #    text_display = json.load(data_file)

    with open("display.json") as data_file:
        text_display = json.load(data_file)

    display = Display(config, text_display, server, log)

    clockThread = ClockThread(True)
Пример #7
0
    def __init__(self, parent, master):
        """ Creating the Interface. Parent in the main function"""
        self.master = master
        self.master.title("SeamCarving")
        # Data
        self.image_name = ""
        self.parent = parent
        self.img_width = 0
        self.img_height = 0
        self.img = None
        self.energy = Energy(self)
        self.resizing = True

        self.nmode_energy = 2
        self.value_energy = [0, 1]
        self.name_energy = ["Gradient", "HOG"]
        self.v_energy = tk.IntVar()

        self.actual_chemin = 0
        self.value_chemin = [0, 1]
        self.name_chemin = ["chemin_less", "NCSC"]
        self.v_chemin = tk.IntVar()

        # Widgets
        self.frame = tk.Frame(master, height=32, width=32)

        self.resize_panel = tk.Frame(self.master)
        self.other_panel = tk.Frame(self.master)
        self.radio_panel = tk.Frame(self.master)
        self.chemin_panel = tk.Frame(self.master)
        self.resize_panel2 = tk.Frame(self.master)

        self.desc_energy = tk.Label(self.radio_panel, text="Mode energy : ")
        self.desc_carving = tk.Label(self.chemin_panel, text="Mode carving : ")

        self.frame.pack()
        self.spin = tk.Spinbox(self.resize_panel, from_=1, to=100)
        self.shrink_vertical_button = tk.Button(
            self.resize_panel,
            text="Enlever seam horizontale",
            command=lambda: self.on_click(0))
        self.shrink_horizontal_button = tk.Button(
            self.resize_panel,
            text="Enlever seam verticale",
            command=lambda: self.on_click(1))
        self.up_vertical_button = tk.Button(self.resize_panel2,
                                            text="Ajouter horizontale",
                                            command=lambda: self.on_click2(0))
        self.up_horizontal_button = tk.Button(
            self.resize_panel2,
            text="Ajouter verticale",
            command=lambda: self.on_click2(1))

        self.detection = tk.Button(self.other_panel,
                                   text="Detection des visage",
                                   command=self.face_detection)
        self.open_energy_button = tk.Button(self.other_panel,
                                            text="Ouvrir l'image d'énergie",
                                            command=self.display_energy)
        self.open_button = tk.Button(self.frame,
                                     text="Ouvrez une image",
                                     command=self.load_image)
        self.open_button.pack()
Пример #8
0
class MyGUI:
    def __init__(self, parent, master):
        """ Creating the Interface. Parent in the main function"""
        self.master = master
        self.master.title("SeamCarving")
        # Data
        self.image_name = ""
        self.parent = parent
        self.img_width = 0
        self.img_height = 0
        self.img = None
        self.energy = Energy(self)
        self.resizing = True

        self.nmode_energy = 2
        self.value_energy = [0, 1]
        self.name_energy = ["Gradient", "HOG"]
        self.v_energy = tk.IntVar()

        self.actual_chemin = 0
        self.value_chemin = [0, 1]
        self.name_chemin = ["chemin_less", "NCSC"]
        self.v_chemin = tk.IntVar()

        # Widgets
        self.frame = tk.Frame(master, height=32, width=32)

        self.resize_panel = tk.Frame(self.master)
        self.other_panel = tk.Frame(self.master)
        self.radio_panel = tk.Frame(self.master)
        self.chemin_panel = tk.Frame(self.master)
        self.resize_panel2 = tk.Frame(self.master)

        self.desc_energy = tk.Label(self.radio_panel, text="Mode energy : ")
        self.desc_carving = tk.Label(self.chemin_panel, text="Mode carving : ")

        self.frame.pack()
        self.spin = tk.Spinbox(self.resize_panel, from_=1, to=100)
        self.shrink_vertical_button = tk.Button(
            self.resize_panel,
            text="Enlever seam horizontale",
            command=lambda: self.on_click(0))
        self.shrink_horizontal_button = tk.Button(
            self.resize_panel,
            text="Enlever seam verticale",
            command=lambda: self.on_click(1))
        self.up_vertical_button = tk.Button(self.resize_panel2,
                                            text="Ajouter horizontale",
                                            command=lambda: self.on_click2(0))
        self.up_horizontal_button = tk.Button(
            self.resize_panel2,
            text="Ajouter verticale",
            command=lambda: self.on_click2(1))

        self.detection = tk.Button(self.other_panel,
                                   text="Detection des visage",
                                   command=self.face_detection)
        self.open_energy_button = tk.Button(self.other_panel,
                                            text="Ouvrir l'image d'énergie",
                                            command=self.display_energy)
        self.open_button = tk.Button(self.frame,
                                     text="Ouvrez une image",
                                     command=self.load_image)
        self.open_button.pack()

    def display_energy(self):
        '''Créer un pop-up permettant de changer manuellement les valeurs d'énergie'''
        tmp = Image.new('L', (self.img_width, self.img_height))
        tmp.putdata(self.energy.energy_tab)
        board = SetEnergyBoard(self.master, tmp, self.img_width,
                               self.img_height).getTab()
        if board:
            self.energy.energy_tab = board

    def get_filename_choosed(self):
        logging.info("Creating dialog to choose an image to open")
        filename = filedialog.askopenfilename(parent=self.master,
                                              title='Ouvrez une image',
                                              initialdir=Utils.IMAGE_PATH)
        if filename:
            logging.info("opening " + filename)
            return filename
        else:
            logging.info("Opening file cancelled")

    def load_image(self):
        self.image_name = self.get_filename_choosed()
        if self.image_name:
            if not self.img:
                self.img = Image.open(self.image_name)
                img = ImageTk.PhotoImage(self.img)
                self.img_width, self.img_height = self.img.size
                self.label = tk.Label(self.master, image=img)
                self.label.image = img  # obligatoire sinon tkinter bug

                self.energy.update_values(self.img_width,
                                          self.img_height,
                                          image=self.img)

                self.label.bind("<Configure>", self.onResize)
                self.detection.pack(side=tk.LEFT)
                self.open_energy_button.pack(side=tk.LEFT)
                self.load_frame()

                self.desc_energy = tk.Label(self.radio_panel,
                                            text="Mode energy : ")
                self.desc_energy.pack(side=tk.LEFT)
                for i in range(self.nmode_energy):
                    b = tk.Radiobutton(self.radio_panel,
                                       variable=self.v_energy,
                                       text=self.name_energy[i],
                                       value=self.value_energy[i],
                                       command=self.click_radio)
                    b.pack(side=tk.LEFT)

                self.desc_carving.pack(side=tk.LEFT)
                for i in range(2):
                    b = tk.Radiobutton(self.chemin_panel,
                                       variable=self.v_chemin,
                                       text=self.name_chemin[i],
                                       value=self.value_chemin[i],
                                       command=self.click_radio_chemin)
                    b.pack(side=tk.LEFT)

                self.other_panel.pack()
                self.resize_panel.pack()
                self.resize_panel2.pack()
                self.radio_panel.pack()
                self.chemin_panel.pack()
                self.label.pack(side=tk.BOTTOM)

                self.v_energy.set(0)
                self.v_chemin.set(0)
                self.energy.energy_tab = self.energy.calc_energy(
                    self.energy.imgBW)

    def update_image(self, data, w, h):
        self.img = Image.new('RGB', (w, h))
        self.img.putdata(data)
        img = ImageTk.PhotoImage(self.img)
        self.label.configure(image=img)
        self.label.image = img  # obligatoire
        self.img_width, self.img_height = self.img.size
        self.load_frame()

    def load_frame(self):
        logging.info("creating Frame")
        self.resizing = True
        self.open_button.pack_forget()
        self.shrink_vertical_button.pack(side=tk.LEFT)
        self.shrink_horizontal_button.pack(side=tk.LEFT)

        self.up_vertical_button.pack(side=tk.LEFT)
        self.up_horizontal_button.pack(side=tk.LEFT)
        self.spin.pack(side=tk.LEFT)

    def exit_program(self, a1, a2):
        logging.info("closing the GUI")
        logging.info("****Closing session*****")
        self.master.main_quit()

    def on_click(self, orientation):
        self.energy.shrink_image(int(self.spin.get()), self.v_chemin.get(),
                                 orientation)

    def on_click2(self, orientation):
        self.energy.shrink_image2(int(self.spin.get()), orientation)

    def onResize(self, event):

        newW = event.width
        oldW = self.img_width
        newH = event.height
        oldH = self.img_height
        if oldW - newW > 0:
            self.img_width = newW
            self.energy.shrink_image(oldW - newW, self.actual_chemin, 1)
        elif oldW - newW < 0 and not self.resizing:
            self.img_width = newW

            self.energy.shrink_image2(newW - oldW, 1)

        if oldH - newH > 0:
            self.img_height = newH
            self.energy.shrink_image(oldH - newH, self.actual_chemin, 0)
        elif oldH - newH < 0 and not self.resizing:
            self.img_height = newH
            self.energy.shrink_image2(newH - oldH, 0)
        self.resizing = False

    def face_detection(self):
        self.energy.detection()

    def click_radio(self):
        v = self.v_energy.get()
        if v == 0:
            self.energy.energy_tab = self.energy.calc_energy(self.energy.imgBW)
        elif v == 1:
            self.energy.energy_tab = self.energy.calc_energy_hog(
                self.energy.imgBW)

    def click_radio_chemin(self):
        self.actual_chemin = self.v_chemin.get()

    def show_image(self):
        self.img.show()