Skip to content
Snippets Groups Projects
Commit b7dc48ae authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

scheduling test - may be shifted to another repo

parent a6264978
Branches
Tags
No related merge requests found
from DecMCTS import Tree
import numpy.random as rand
# Creat a bunch of jobs
# Each job has a time to do (in seconds?)
# Each job has an x-y location (0-1 m)
# Each job pair has a time to travel between them (fixed velocity m/s)
n_jobs = 20
job_time_min = 0
job_time_max = 10
vel = 0.1
rand.seed(1)
job_locs = [(x,y) for x,y in zip(rand.rand(n_jobs), rand.rand(n_jobs))]
job_times = [job_time_min+(job_time_max-job_time_min)*t
for t in rand.rand(n_jobs)]
def dist(p1,p2):
return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)**0.5
travel_time = {(j1,j2):dist(job_locs[j1], job_locs[j2])/vel
for j1 in range(n_jobs)
for j2 in range(n_jobs)}
# Data needed for any calculations
data = {
"job_locs": job_locs,
"job_times": job_times
"tt": travel_time
}
# State For a particular robot
class State:
def __init__(self, start_pos):
self.jobs = []
self.time_so_far = 0
self.time_wasted = 0
self.current_pos = start_pos
def append(self, new_job):
self.jobs.append(new_job)
self.time_so_far += data["tt"][self.jobs[-1], self.jobs[-2]] \
+ job_times[new_job]
self.time_wasted += data["tt"][self.jobs[-1], self.jobs[-2]]
self.current_pos = job_locs[new_job]
def state_storer(data, parent_state, action):
if parent_state == None:
return State((0,0)) # This state is also used Null action when calculating local reward
state = deepcopy(parent_state)
state.append(action)
return state
# All actions not done by the current robot are considered available
# actions of other robots are not considered
def avail_actions(data, states, robot_id):
return [j for j in list(range(n_jobs)) if j not in states[robot_id].jobs]
# reward is inversely proportional to total time taken
def reward(dat, states):
time_wasted = [states[robot].time_wasted for robot in states]
return 1/sum(each_robot_sum)
# Communicate top n nodes of the MCTS tree
comm_n = 5
# Create the trees
n_robots = 2
trees = [None]*n_robots
for i in range(n_robots):
trees[i] = Tree(data, reward, avail_actions, state_storer, comm_n, i)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment