-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed row and column cogs from being excluded. #1
base: main
Are you sure you want to change the base?
Conversation
Hi, """
- `excludes_dict[type(cog)]' is a `set' of all coordinates where `cog' should not be placed.
- For example, if `cog' is of type `Up_Cog', then `excludes_dict[type(cog)]' should contain all coords on the top row of
the array.
- This dict is not necessary for the genetic algorithm to find an optimal array. It merely improves the convergence rate.
"""
def get_excludes_dict(empties_set, cogs):
cog_array = Cog_Array(empties_set)
excludes_dict = {}
for cog in cogs:
if type(cog) not in excludes_dict and isinstance(cog, Boost_Cog):
excludes_dict[type(cog)] = set()
for coords in Coords_Iter(cog_array):
num_oob_neighbors = sum((adj_coords.is_out_of_bounds()) for adj_coords in cog.get_influence(coords))
if num_oob_neighbors > cog.get_max_oob_neighbors():
excludes_dict[type(cog)].add(coords)
return excludes_dict Looking at the original code I am also missing the not yet unlocked coordinates treated as being out of bounds. In my opinion you would do that. So I made the following changes. num_oob_neighbors = sum((adj_coords.is_out_of_bounds() or adj_coords in empties_set) for adj_coords in cog.get_influence(coords)) Furthermore, we need to address the way Row en Col cogs are calculating their influence. This is done inside "cog_types.py". class Row_Cog(Boost_Cog):
def get_influence(self,coords):
return map(
lambda t: coords + Coords(t[0],t[1]),
[(x,0) for x in itertools.chain(range(-NUM_COGS_HORI,0),range(1,NUM_COGS_HORI+1))]
)
def get_abbr(self):
return "-"
def get_max_oob_neighbors(self):
return NUM_COGS_HORI
class Col_Cog(Boost_Cog):
def get_influence(self,coords):
return map(
lambda t: coords + Coords(t[0],t[1]),
[(0,y) for y in itertools.chain(range(-NUM_COGS_VERT,0),range(1,NUM_COGS_VERT+1))]
)
def get_abbr(self):
return "|"
def get_max_oob_neighbors(self):
return NUM_COGS_VERT Here I made the following adjustments. First, the influence is not calculated correctly. For example, the Col cog has influence on all other cogs in the same column. However, the original code checks "NUM_COGS_VERT" number of coordinates in each direction, but the since the Col cog is also part of the column it has to check "-1". So "-NUM_COGS_VERT+1" and "NUM_COGS_VERT+1-1". def get_influence(self,coords):
return map(
lambda t: coords + Coords(t[0],t[1]),
[(0,y) for y in itertools.chain(range(-NUM_COGS_VERT+1,0),range(1,NUM_COGS_VERT))]
)
# and the Row col will be
[(x,0) for x in itertools.chain(range(-NUM_COGS_HORI+1,0),range(1,NUM_COGS_HORI))] So this fixes the number of coordinates influenced by the Row and Col cogs, but it does not address the number of max allowed out of bounds coordinates. def get_max_oob_neighbors(self):
return (NUM_COGS_VERT-1) + ((NUM_COGS_VERT-1) / 2)
# But this could be a float in the case of odd numbers, so the make sure we have an integer rounded up. (this way you dont need to import the math library, you could also use ceil function of math library)
return (NUM_COGS_VERT-1) + (int(((NUM_COGS_VERT-1) / 2)) + (((NUM_COGS_VERT-1) % 2) > 0))
# And for the Row cog
return (NUM_COGS_HORI-1) + (int(((NUM_COGS_HORI-1) / 2)) + (((NUM_COGS_HORI-1) % 2) > 0)) I was too lazy to fork and commit my code, so I made this write up. If someone has any questions let me know. |
No description provided.