Skip to content

Commit

Permalink
Update behaviors.py
Browse files Browse the repository at this point in the history
A "normalized" option was implemented in the lennard_jones behavior.
  • Loading branch information
mrsonandrade committed Oct 25, 2023
1 parent 9585691 commit b5ef5cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Tests](https://github.com/mrsonandrade/pyswarming/actions/workflows/tests_package.yml/badge.svg)](https://github.com/mrsonandrade/pyswarming/actions/workflows/tests_package.yml)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Documentation Status](https://readthedocs.org/projects/pyswarming/badge/?version=latest)](https://pyswarming.readthedocs.io/en/latest/?badge=latest)
![version](https://img.shields.io/badge/version-1.1.4-blue)
![version](https://img.shields.io/badge/version-1.1.5-blue)
[![Downloads](https://static.pepy.tech/personalized-badge/pyswarming?period=total&units=none&left_color=black&right_color=blue&left_text=Downloads)](https://pepy.tech/project/pyswarming)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.05647/status.svg)](https://doi.org/10.21105/joss.05647)

Expand Down
2 changes: 1 addition & 1 deletion pyswarming/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
__all__.append(module_j)

name = "pyswarming"
__version__ = "1.1.4"
__version__ = "1.1.5"
__author__ = "Emerson Martins de Andrade, Antonio Carlos Fernandes and Joel Sena Sales Jr"
__author_email__ = "[email protected]"
14 changes: 12 additions & 2 deletions pyswarming/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def preferred_direction(theta_i, k_i, w=0.0):
return new_theta_i


def lennard_jones(r_i, r_j, epsilon, sigma):
def lennard_jones(r_i, r_j, epsilon, sigma, normalized=False):
"""
Calculates an output force that produces
lattice formations, based on the "Lennard-Jones
Expand All @@ -538,6 +538,10 @@ def lennard_jones(r_i, r_j, epsilon, sigma):
sigma : float
desired distance between the robots.
normalized : boolean
boolean parameter to normalize each
term in the sum when normalized = True.
Returns
-------
f_i : numpy.array
Expand All @@ -550,7 +554,13 @@ def lennard_jones(r_i, r_j, epsilon, sigma):

for j in r_j:
r_ij = (j - r_i)
f_i += ((12.0*epsilon)/r_ij) * (np.power(sigma/r_ij, 12) - np.power(sigma/r_ij, 6)) * (r_ij / np.linalg.norm(r_ij))

if normalized == True:
normalization_term = (r_ij / np.linalg.norm(r_ij))
else:
normalization_term = 1.0

f_i += ((12.0*epsilon)/r_ij) * (np.power(sigma/r_ij, 12) - np.power(sigma/r_ij, 6)) * normalization_term

f_i = (1.0/N) * f_i

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setuptools.setup(
name="pyswarming",
version="1.1.4",
version="1.1.5",
author="Emerson Martins de Andrade",
author_email="[email protected]",
description="A research toolkit for Swarm Robotics",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_lennard_jones():
for r_ind in range(len(r)):
r_i = r[r_ind]
r_j = np.delete(r, np.array([r_ind]), axis=0)
f[r_ind] += pb.lennard_jones(r_i, r_j, epsilon, sigma)
f[r_ind] += pb.lennard_jones(r_i, r_j, epsilon, sigma, normalized=True)
assert type(f) == np.ndarray
assert len(f) > 0
assert (f!=f0).all() == True
Expand Down

0 comments on commit b5ef5cd

Please sign in to comment.