Skip to content

Commit

Permalink
Fixes generating parameters using circle-based generator
Browse files Browse the repository at this point in the history
  • Loading branch information
afsafzal committed Aug 9, 2019
1 parent 2edbe20 commit a11b09b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
21 changes: 13 additions & 8 deletions experiments/generate_missions_templatebased.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def generate(num_missions: int,
seed=args.seed,
speedup=args.speedup,
template=args.t)
mission_descriptions = list(map(Mission.to_dict, missions))
elif args.f:
templates = []
with open(args.f, "r") as f:
Expand All @@ -83,28 +84,32 @@ def generate(num_missions: int,
if not template:
continue
if isinstance(template, str):
templates.append((template, args.number_of_mission))
templates.append((template, args.number_of_mission, m['uid']))
elif isinstance(template, list):
n_missions = args.number_of_mission
for i, t in enumerate(template):
if i == len(template)-1:
templates.append((t, n_missions))
templates.append((t, n_missions, m['uid']))
else:
r = random.randint(0, n_missions)
templates.append((t, r))
templates.append((t, r, m['uid']))
n_missions -= r
logger.info("Number of templates: %d", len(templates))
logger.info("AAAA %s", templates)
missions = []
for template, num in templates:
missions.extend(generate(num_missions=num,
mission_descriptions = []
for template, num, uid in templates:
missions = generate(num_missions=num,
max_num_commands=args.max_num_commands,
seed=args.seed,
speedup=args.speedup,
template=template))
template=template)
for n in missions:
new_dict = n.to_dict()
new_dict['mutant'] = uid
mission_descriptions.append(new_dict)
else:
raise Exception("Provide either -t or -f")

logger.info("Total number of missions: %d", len(mission_descriptions))
with open(args.output, "w") as f:
mission_descriptions = list(map(Mission.to_dict, missions))
json.dump(mission_descriptions, f, indent=2)
8 changes: 6 additions & 2 deletions houston/ardu/command_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ def circle_based_generator(cls: Type[Command],
destination = dist.destination(origin, heading)

prob_zero = 0.1 # the probability of generating 0.0 as the parameter value
params['lat'] = destination.latitude if rng.random() >= prob_zero else 0.0
params['lon'] = destination.longitude if rng.random() >= prob_zero else 0.0
if rng.random() >= prob_zero:
params['lat'] = destination.latitude
params['lon'] = destination.longitude
else:
params['lat'] = 0.0
params['lon'] = 0.0

command = cls(**params)
return command
Expand Down
5 changes: 3 additions & 2 deletions houston/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,13 @@ def generate_fixed_params(cls,
fixed_params: Dict[str, Any],
rng: random.Random
) -> 'Command':
new_cmd = cls.generate(rng)
params = {}
for p in cls.parameters:
for p in new_cmd:
if p.name in fixed_params.keys():
params[p.name] = fixed_params[p.name]
else:
params[p.name] = p.generate(rng)
params[p.name] = new_cmd[p.name]
command = cls(**params)
return command

Expand Down

0 comments on commit a11b09b

Please sign in to comment.