Skip to content

Commit

Permalink
Three examples tested
Browse files Browse the repository at this point in the history
  • Loading branch information
aadeshnpn committed Feb 27, 2019
1 parent 777e54d commit c29cc3f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
6 changes: 4 additions & 2 deletions examples/nest_maintainence/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def simulate(env, iteration, N=100):
threshold = 1.0

sim = SimModel(
N, 100, 100, 10, seed=None, iter=iteration, xmlstrings=phenotypes, pname=env[1])
N, 100, 100, 10, seed=None, iter=iteration,
xmlstrings=phenotypes, pname=env[1])
sim.build_environment_from_json()

# print(len(sim.obstacles), len(sim.debris))
Expand Down Expand Up @@ -181,7 +182,8 @@ def main(iter):
"""Block for the main function."""
print('=======Start=========')
# env = evolve(iter)
pname = '/home/aadeshnpn/Documents/BYU/hcmi/hri/nest_maint/10000NestMAgents'
pname = (
'/home/aadeshnpn/Documents/BYU/hcmi/hri/nest_maint/10000NestMAgents')
jfilename = pname + '/1539014820252.json'
jdata = JsonPhenotypeData.load_json_file(jfilename)
phenotypes = jdata['phenotypes']
Expand Down
10 changes: 5 additions & 5 deletions examples/nest_maintainence_evolution/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from swarms.utils.results import SimulationResults
# import py_trees
# Global variables for width and height
width = 100
height = 100
width = 200
height = 200

UI = False

Expand Down Expand Up @@ -112,7 +112,7 @@ def learning_phase(iteration, early_stop=False):
phenotype_to_json(
env.pname, env.runid, phenotypes)
validation_loop(
phenotypes, 5000, phenotypes)
phenotypes, 5000, parentname=env.pname)
except ValueError:
pass
# Plot the fitness in the graph
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_json_phenotype(json):
# Running 50 experiments in parallel
# Parallel(n_jobs=8)(delayed(main)(i) for i in range(2000, 100000, 2000))
# Parallel(n_jobs=4)(delayed(main)(i) for i in range(1000, 8000, 2000))
# main(8000)
main(8000)
# json = '1543367322976111-5999.json'
# test_json_phenotype(json)
Parallel(n_jobs=4)(delayed(main)(8000) for i in range(128))
# Parallel(n_jobs=4)(delayed(main)(8000) for i in range(128))
4 changes: 2 additions & 2 deletions examples/nest_maintainence_evolution/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def gather_info(self):
for id in range(len(self.agents)):
# diversity[id] = self.agents[id].diversity_fitness
exploration[id] = self.agents[id].exploration_fitness()
foraging[id] = self.agents[id].food_collected
foraging[id] = self.agents[id].debris_collected
fittest[id] = self.agents[id].individual[0].fitness
prospective[id] = self.agents[id].carrying_fitness()

Expand Down Expand Up @@ -213,7 +213,7 @@ def best_agents(self, data, beta, header):
idx = np.argmax(data)
# dfitness = self.agents[idx].diversity_fitness
ofitness = self.agents[idx].individual[0].fitness
ffitness = self.agents[idx].food_collected
ffitness = self.agents[idx].debris_collected
efitness = self.agents[idx].exploration_fitness()
pfitness = self.agents[idx].carrying_fitness()
phenotype = self.agents[idx].individual[0].phenotype
Expand Down
11 changes: 11 additions & 0 deletions grammars/sf.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<s> ::= [?xml version=%1.0% encoding=%UTF-8%?]<cf>
<cf> ::= <sequence> | <selector>
<sequence> ::= [Sequence]<execution>[/Sequence] | [Sequence]<cf><cf>[/Sequence] | [Sequence]<sequence> <cf>[/Sequence]
<selector> ::= [Selector]<execution>[/Selector] | [Selector]<cf><cf>[/Selector] | [Selector]<selector> <cf>[/Selector]
<execution>::=<conditions>[act]<action>[/act]
<conditions>::=[cond]<condition>[/cond]<conditions>|[cond]<condition>[/cond]
<condition>::=NeighbourObjects|IsDropable_<sobjects>|NeighbourObjects_<objects>|NeighbourObjects_<objects>_invert|IsVisitedBefore_<sobjects>|IsVisitedBefore_<sobjects>_invert|IsCarrying_<dobjects>|IsCarrying_<dobjects>_invert
<action>::=MoveTowards_<sobjects>|Explore|CompositeSingleCarry_<dobjects>|CompositeDrop_<dobjects>|MoveAway_<sobjects>
<sobjects>::=Hub|Sites
<dobjects>::=Food
<objects>::=<sobjects>|<dobjects>
8 changes: 4 additions & 4 deletions parameters/nm.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE: True
CODON_SIZE: 1000
CODON_SIZE: 2000
CROSSOVER: variable_onepoint
CROSSOVER_PROBABILITY: 0.9
DEBUG: False
Expand All @@ -8,10 +8,10 @@ MAX_GENOME_LENGTH: 50
GRAMMAR_FILE: ../..,nm.bnf
INITIALISATION: uniform_tree
INVALID_SELECTION: False
MAX_INIT_TREE_DEPTH: 5
MAX_TREE_DEPTH: 12
MAX_INIT_TREE_DEPTH: 7
MAX_TREE_DEPTH: 10
MUTATION: int_flip_per_codon
MUTATION_PROBABILITY: 0.09
MUTATION_PROBABILITY: 0.1
FITNESS_FUNCTION: swarm.bt_diversity
REPLACEMENT: generational
SELECTION: truncation
Expand Down

0 comments on commit c29cc3f

Please sign in to comment.