MOPSO transition
This commit is contained in:
32
particle.py
32
particle.py
@@ -1,7 +1,7 @@
|
||||
import random as rd
|
||||
|
||||
class Particle():
|
||||
def __init__(self, nb_vehicles:int=10, delta_t:int=60, nb_of_ticks:int=72, a_min=-100, a_max=100, alpha=0.1):
|
||||
def __init__(self, times:list, nb_vehicles:int=10, delta_t:int=60, nb_of_ticks:int=72, x_min=-100, x_max=100, alpha=0.1):
|
||||
# Problem specific attributes
|
||||
self.nb_vehicles = nb_vehicles # Number of vehicles handles for the generations of position x
|
||||
self.delta_t = delta_t # delta_t for update purposes
|
||||
@@ -9,12 +9,11 @@ class Particle():
|
||||
|
||||
self.socs= self.generate_state_of_charges() # States of charge (initial, requested)
|
||||
|
||||
#TODO: Move that to MOPSO (using one batch of times for multiples particles)
|
||||
self.times = self.generate_times() # Times (arrived, leaving)
|
||||
self.times = times # (arrived, leaving)
|
||||
|
||||
# Minima and maxima of a position value
|
||||
self.a_min = a_min
|
||||
self.a_max = a_max
|
||||
self.x_min = x_min
|
||||
self.x_max = x_max
|
||||
|
||||
# Limitation of the velocity
|
||||
self.alpha = alpha
|
||||
@@ -36,24 +35,6 @@ class Particle():
|
||||
for i in range(self.nb_vehicles):
|
||||
new_vel_i = w * self.v[i] + (self.p_best - self.x[i]) * c1 * self.r1[i] + (leader - self.x[i]) * c2 * self.r2[i]
|
||||
self.v[i] = new_vel_i
|
||||
|
||||
def generate_state_of_charges(self):
|
||||
socs = []
|
||||
# We ensure soc_req is greater than what the soc_init is (percentage transformed into floats)
|
||||
for _ in range(self.nb_vehicles):
|
||||
soc_init = rd.randrange(0,100,1)
|
||||
soc_req = rd.randrange(soc_init+1, 101,1)
|
||||
socs.append((soc_init/100, soc_req/100))
|
||||
return socs
|
||||
|
||||
def generate_times(self):
|
||||
times = []
|
||||
for _ in range(self.nb_vehicles):
|
||||
# Minumun, we have one tick of charging during simulation
|
||||
t_arrived = rd.randrange(0, (self.nb_of_ticks * self.delta_t - self.delta_t) +1, self.delta_t)
|
||||
t_leaving = rd.randrange(t_arrived + self.delta_t, (self.nb_of_ticks*self.delta_t)+1, self.delta_t)
|
||||
times.append((t_arrived,t_leaving))
|
||||
return times
|
||||
|
||||
#TODO: Modify for uses of ticks
|
||||
def generate_position(self):
|
||||
@@ -61,13 +42,14 @@ class Particle():
|
||||
for _ in range(self.nb_of_ticks):
|
||||
x_tick = []
|
||||
for _ in range(self.nb_vehicles):
|
||||
x_tick.append(rd.randrange(self.a_min, self.a_max +1, 1))
|
||||
x_tick.append(rd.randrange(self.x_min, self.x_max +1, 1))
|
||||
pos.append(x_tick)
|
||||
return pos
|
||||
|
||||
# Randomize a velocity vector for each tick
|
||||
def generate_velocity(self):
|
||||
vel = []
|
||||
vel_coeff = self.a_max - self.a_min
|
||||
vel_coeff = abs(self.x_max - self.x_min)
|
||||
for _ in range(self.nb_of_ticks):
|
||||
v_tick = []
|
||||
for _ in range(self.nb_vehicles):
|
||||
|
||||
Reference in New Issue
Block a user