class PSO:
    def __init__(self, costFunc, x0, bounds, num_particles, maxiter):
        global num_dimensions

        num_dimensions = len(x0)
        err_best_g = -1  # best error for group
        pos_best_g = []  # best position for group

        # establish the swarm
        swarm = []
        for i in range(0, num_particles):
            swarm.append(Particle(x0))

        # begin optimization loop
        i = 0
        while i < maxiter:
            # print i,err_best_g
            # cycle through particles in swarm and evaluate fitness
            for j in range(0, num_particles):
                swarm[j].evaluate(costFunc)

                # determine if current particle is the best (globally)
                if swarm[j].err_i < err_best_g or err_best_g == -1:
                    pos_best_g = list(swarm[j].position_i)
                    err_best_g = float(swarm[j].err_i)

            # cycle through swarm and update velocities and position
            for j in range(0, num_particles):
                swarm[j].update_velocity(pos_best_g)
                swarm[j].update_position(bounds)
            i += 1

        # print final results
        print('FINAL:')
        print (pos_best_g)
        print (err_best_g)

    main()
Example #2
0
    # read methoud
    read = lambda self: self.collection.find({})
    # insert methoud
    insert = lambda self, name, lname: \
        self.collection.insert_one({"name":name, "lname": lname})
    # update methoud
    update = lambda self, name: self.collection.find_one_and_update(
        {"name": "ismail"}, {"$set": {
            "name": name
        }})
    # delete methoud
    delete = lambda self, name: \
        self.collection.find_one_and_delete({"name": name})


if __name__ == "__main__":
    mongo = Mongo()
    # read
    students = [student for student in mongo.read()]
    print(students[::-1])
    # inser
    # insert = mongo.insert('zouheir', 'salmi')
    # print(insert, 'is inserted')
    #update
    # update = mongo.update('samir')
    # print(update, 'is updated')
    # delete
    # delete = mongo.delete('samir')
    # print(delete , "is deleted")
    main()
Example #3
0
            urconv = npsbot.find_element_by_id('yourcon1')
            firstv = npsbot.find_element_by_id('firstv1')
            wastechcou = npsbot.find_element_by_id('wastechcou1')
            chargingtech = npsbot.find_element_by_id('chargingtech1')
            # 3 stars
            starratting = npsbot.find_element_by_xpath('/html/body/div/div/div/div[2]/form/div/div[1]/div[7]/div[2]/div/div[1]/input')
            actions = ActionChains(npsbot)

            scalerate = npsbot.find_element_by_id('ratingpremain10')
            remarks = npsbot.find_element_by_id('remarksbreak').send_keys('good service')
            submit = npsbot.find_element_by_id('submit')

            #pyautogui.click(792, 265)
            # Do Action on elements
            urconv.click()
            firstv.click()
            wastechcou.click()
            chargingtech.click()
            #starratting.click()
            actions.click(starratting)
            actions.perform()
            scalerate.click()
            time.sleep(1)
            submit.click()
            time.sleep(2)
    except Exception as e:
        print(e)
npsbot.quit()

if __name__ == '__manin__': main()
Example #4
0
 def update_event(self, inp=-1):
     self.set_output_val(0, base64.main())