Skip to content

Commit

Permalink
Correct energy_consumption in neurotoxin env
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Nov 11, 2024
1 parent 3ffbad7 commit f002c42
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/emevo/environments/circle_foraging_with_neurotoxin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ def step( # type: ignore
)
toxin_decay = jnp.expand_dims(1.0 - toxin_decay_rate, axis=1)
# Add force
act = jax.vmap(self.act_space.clip)(jnp.array(action)) * toxin_decay
act = jax.vmap(self.act_space.clip)(jnp.array(action))
f1_raw = jax.lax.slice_in_dim(act, 0, 1, axis=-1)
f2_raw = jax.lax.slice_in_dim(act, 1, 2, axis=-1)
f1 = jnp.concatenate((jnp.zeros_like(f1_raw), f1_raw), axis=1)
f2 = jnp.concatenate((jnp.zeros_like(f2_raw), f2_raw), axis=1)
circle = state.physics.circle
circle = circle.apply_force_local(self._act_p1, f1)
circle = circle.apply_force_local(self._act_p2, f2)
# Decay force by toxin
circle = circle.apply_force_local(self._act_p1, f1 * toxin_decay)
circle = circle.apply_force_local(self._act_p2, f2 * toxin_decay)
stated = replace(state.physics, circle=circle)
# Step physics simulator
stated, solver, nstep_contacts = nstep(
Expand Down

0 comments on commit f002c42

Please sign in to comment.