Ejemplo n.º 1
0
  def setUp(self):
    configFileName = "solipsis.conf"
    param = Parameters(configFileName)
    n = Node(param)            
    self.manager = PeersManager(n, param.getPeersParams())
    
    p0 = Peer("0","h1","1",[0,0])
    p1 = Peer("1","h1","2",[0,10])
    p2 = Peer("2","h1","3",[5,0])
    p3 = Peer("3","h1","3",[5,20])
    p4 = Peer()
		
    self.peers = [p0, p1, p2, p3, p4]
Ejemplo n.º 2
0
    epsilon = 1.0
    epsilon_min = 0.1
    alpha = 0.001
    gamma = 0.01
    decay = 0.9
    replace_target_iter = 1
    memory_size = 200
    batch_size = 32
    use_seed = True
    training_seed = 1
    test_seed = 1

    debug_print = True

    '___ENVIRONMENT PARAMETERS___'
    environment_parameters = Parameters()

    '___CREATE TEST FOLDER___'
    path = create_test_folder('ai')
    writeParameterToFile(environment_parameters, training_episodes,
                         testing_episodes, epsilon, epsilon_min, alpha, gamma,
                         decay, replace_target_iter, memory_size, batch_size,
                         use_seed, path, test_seed)
    if (debug_print == True):
        print("Parameter written to Test folder.")

    '___DATA GENERATION___'
    generator = DataGenerator(use_seed, environment_parameters)
    training_data = generator.generateDataSet(training_episodes, training_seed)
    test_data = generator.generateDataSet(testing_episodes, test_seed)
    if (debug_print == True):
Ejemplo n.º 3
0
    def __init__(self, numIt, nPop, filename):
        it = 0

        filename = os.getcwd() + '/' + filename

        # Read input file
        if rank == 0:
            self.parameters = Parameters(filename)
            self.temperatures = Temperatures(filename)
            self.simulation = Simulation(filename)
            self.psoparameters = ParticleSwarmParameters(filename)
        else:
            self.parameters = None
            self.temperatures = None
            self.simulation = None
            self.psoparameters = None

        self.parameters = comm.bcast(self.parameters, root=0)
        self.temperatures = comm.bcast(self.temperatures, root=0)
        self.simulation = comm.bcast(self.simulation, root=0)
        self.psoparameters = comm.bcast(self.psoparameters, root=0)

        # Initilize some variables
        number_of_temperatures = self.temperatures.GetDim()
        w = self.psoparameters.w
        c1 = self.psoparameters.c1
        c2 = self.psoparameters.c2

        if rank == 0:
            swarm = [
                Particle(self.parameters, self.temperatures, self.simulation)
                for i in range(nPop)
            ]
        else:
            swarm = None

        if rank == 0:
            Utility.LogMessage('Scattering the initial swarm')
        particle = comm.scatter(swarm, root=0)

        if rank == 0:
            Utility.LogMessage('Initializing the costs for the swarm')
        particle.Evaluate(it)
        particle.UpdateBestPosition()
        comm.barrier()

        if rank == 0:
            Utility.LogMessage('Gathering all the costs back to node 0')
        swarm = comm.gather(particle, root=0)

        if rank == 0:
            length = len(swarm)
            for i in range(length):
                if i % number_of_temperatures == 0:
                    Utility.PrintCoordinates(it, swarm[i])

        if rank == 0:
            best_particle = Utility.GetBestParticle(swarm,
                                                    number_of_temperatures)
            Utility.LogMessage('Best global cost: {}, {}, {}, {}'.format(
                best_particle.cost, best_particle.pars, best_particle.pos,
                best_particle.dens))
        it += 1
        while it <= numIt:
            if rank == 0:
                Utility.LogMessage('Starting iteration {}'.format(it))
                for i in range(len(swarm)):
                    if i % number_of_temperatures == 0:
                        p = swarm[i]
                        p.CalculateNextVelocity(w, c1, c2, best_particle.pos)
                        p.CalculateNextPosition()

            particle = comm.scatter(swarm, root=0)
            particle.Evaluate(it)
            particle.UpdateBestPosition()
            swarm = comm.gather(particle, root=0)

            if rank == 0:
                length = len(swarm)
                for i in range(length):
                    if i % number_of_temperatures == 0:
                        Utility.PrintCoordinates(it, swarm[i])

            if rank == 0:
                best_p = Utility.GetBestParticle(swarm, number_of_temperatures)
                if best_p.cost < best_particle.cost:
                    best_particle = best_p
                    Utility.LogMessage(
                        'Found better global cost: {}, {}, {}'.format(
                            best_particle.cost, best_particle.pos,
                            best_particle.dens))
                else:
                    Utility.LogMessage(
                        'Old global best is still better! {}, {}, {}'.format(
                            best_particle.cost, best_particle.pos,
                            best_particle.dens))
            it += 1
Ejemplo n.º 4
0
import xmlrpclib
import curses.wrapper
from parameter import Parameters
from controller import Controller
import sys

configFileName = "solipsis.conf"

param = Parameters(configFileName)
[host, port, logger] = param.getControlParams()

controller = Controller([host, port, logger])

def window(stdscr2):
    #begin_x = 20 ; begin_y = 7
    #height = 5 ; width = 40
    #stdscr = curses.newwin(height, width, begin_y, begin_x)

    stdscr = curses.newwin(4,80,0,0)
    responsewin = curses.newwin(5,15)

    #stdscr.addstr( "Pretty text", curses.color_pair(1) )
    stdscr.addstr( "Solipsis navigator")
    stdscr.addstr( 1, 0, "Press q to quit, s to start a new node, " +
                   "i for node info, k to kill node")
    stdscr.refresh()

    while 1:
        c = stdscr.getch()
        try:
            if c == ord('q'): break
Ejemplo n.º 5
0
#     import time
#
#     start_time = time.time()
#     for i in xrange(100000):
#         a = other_agents.get_sjf_action(env.machine, env.job_slot)
#         env.step(a)
#     end_time = time.time()
#     print
#     "- Elapsed time: ", end_time - start_time, "sec -"


if __name__ == '__main__':
    # test_backlog()
    # test_compact_speed()
    # test_image_speed()
    pa = Parameters()
    pa.simu_len = 20
    pa.num_res = 2
    env = Env(pa)

    env.step(5,0)
    env.step(5,0)
    env.step(5,1)
    env.step(5,1)
    env.step(5,1)
    env.step(1,1)
    env.step(2,0)
    env.step(1,0)
    env.step(5,0)

    # env.step(0)
Ejemplo n.º 6
0
    def __init__(self, numIt, nPop, filename):
        it = 0

        # Read input file
        if rank == 0:
            self.parameters = Parameters(filename)
            self.temperatures = Temperatures(filename)
            self.system = System(filename)
            self.psoparameters = ParticleSwarmParameters(filename)
            self.charges = Charges(filename)
        else:
            self.parameters = None
            self.temperatures = None
            self.system = None
            self.psoparameters = None
            self.charges = None

        self.parameters = comm.bcast(self.parameters, root=0)
        self.temperatures = comm.bcast(self.temperatures, root=0)
        self.system = comm.bcast(self.system, root=0)
        self.psoparameters = comm.bcast(self.psoparameters, root=0)
        self.charges = comm.bcast(self.charges, root=0)

        # Equilibrate all simulations
        if rank == 0:
            Utility.LogMessage('Generate files for equilibrium')
            Utility.GenerateFilesForEquilibrate(self.temperatures,
                                                self.parameters, self.system,
                                                self.charges)
            Utility.LogMessage('Done generating equilibrium files')
            Utility.LogMessage('Running equilibrium simulations')
        comm.barrier()
        Utility.RunEquilibrate(self.temperatures)
        comm.barrier()
        if rank == 0:
            Utility.LogMessage('Done equilibrating simulations')

        # Initilize some variables
        dim = self.parameters.GetDim()
        w = self.psoparameters.w
        c1 = self.psoparameters.c1
        c2 = self.psoparameters.c2

        if rank == 0:
            swarm = [
                Particle(self.parameters, self.temperatures)
                for i in range(nPop)
            ]
        else:
            swarm = None

        if rank == 0:
            Utility.LogMessage('Scattering the initial swarm')
        particle = comm.scatter(swarm, root=0)

        if rank == 0:
            Utility.LogMessage('Initializing the costs for the swarm')
        particle.Evaluate(it)
        particle.UpdateBestPosition()
        comm.barrier()

        if rank == 0:
            Utility.LogMessage('Gathering all the costs back to node 0')
        swarm = comm.gather(particle, root=0)

        if rank == 0:
            length = len(swarm)
            for i in range(length):
                if i % 3 == 0:
                    p = swarm[i]
                    Utility.PrintCoordinates(it, p)

        if rank == 0:
            best_particle = Utility.GetBestParticle(swarm)
            Utility.LogMessage('Best global cost: {}, {}, {}, {}'.format(
                best_particle.cost, best_particle.pars, best_particle.pos,
                best_particle.dens))
        it += 1
        while it <= numIt:
            if rank == 0:
                Utility.LogMessage('Starting iteration {}'.format(it))
                for i in range(len(swarm)):
                    if i % 3 == 0:
                        p = swarm[i]
                        p.CalculateNextVelocity(w, c1, c2, best_particle.pos)
                        p.CalculateNextPosition()

            particle = comm.scatter(swarm, root=0)
            particle.Evaluate(it)
            particle.UpdateBestPosition()
            swarm = comm.gather(particle, root=0)

            if rank == 0:
                length = len(swarm)
                for i in range(length):
                    if i % 3 == 0:
                        p = swarm[i]
                        Utility.PrintCoordinates(it, p)

            if rank == 0:
                best_p = Utility.GetBestParticle(swarm)
                if best_p.cost < best_particle.cost:
                    best_particle = best_p
                    Utility.LogMessage(
                        'Found better global cost: {}, {}, {}'.format(
                            best_particle.cost, best_particle.pos,
                            best_particle.dens))
                else:
                    Utility.LogMessage(
                        'Old global best is still better! {}, {}, {}'.format(
                            best_particle.cost, best_particle.pos,
                            best_particle.dens))
            it += 1