-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
663 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
#################################|###|##################################### | ||
# __ | | # | ||
# | |--.--.--.----.-----.-----. |===| This file is part of Byron v0.8 # | ||
# | _ | | | _| _ | | |___| An evolutionary optimizer & fuzzer # | ||
# |_____|___ |__| |_____|__|__| ).( https://github.com/squillero/byron # | ||
# |_____| \|/ # | ||
################################## ' ###################################### | ||
|
||
# Copyright 2023 Giovanni Squillero and Alberto Tonda | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# =[ HISTORY ]=============================================================== | ||
# v1 / August 2023 / Squillero (GX) | ||
|
||
__all__ = ['Node'] | ||
|
||
import networkx as nx | ||
|
||
from byron.tools.graph import fasten_subtree_parameters | ||
from byron.global_symbols import NODE_ZERO | ||
from byron.classes.node_reference import NodeReference | ||
|
||
|
||
class Node(int): | ||
r"""Simple helper to guarantee Node ids uniqueness""" | ||
__slots__ = [] | ||
__LAST_BYRON_NODE = 0 | ||
|
||
def __new__(cls, node_id: int or None = None): | ||
if node_id is not None: | ||
return int.__new__(cls, node_id) | ||
Node.__LAST_BYRON_NODE += 1 | ||
return int.__new__(cls, Node.__LAST_BYRON_NODE) | ||
|
||
@staticmethod | ||
def reset_labels(G: nx.Graph) -> None: | ||
"""Set Graph node labels to unique numbers""" | ||
new_labels = {k: Node() for k in G.nodes if k != NODE_ZERO} | ||
nx.relabel_nodes(G, new_labels, copy=False) | ||
fasten_subtree_parameters(NodeReference(G, NODE_ZERO)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.