You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_map.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Wed Apr 22 11:31:26 2020
  5. @author: ljia
  6. """
  7. import numpy as np
  8. class NodeMap(object):
  9. def __init__(self, num_nodes_g, num_nodes_h):
  10. self.__forward_map = [np.inf] * num_nodes_g
  11. self.__backward_map = [np.inf] * num_nodes_h
  12. self.__induced_cost = np.inf
  13. def num_source_nodes(self):
  14. return len(self.__forward_map)
  15. def num_target_nodes(self):
  16. return len(self.__backward_map)
  17. def image(self, node):
  18. if node < len(self.__forward_map):
  19. return self.__forward_map[node]
  20. else:
  21. raise Exception('The node with ID ', str(node), ' is not contained in the source nodes of the node map.')
  22. return np.inf
  23. def pre_image(self, node):
  24. if node < len(self.__backward_map):
  25. return self.__backward_map[node]
  26. else:
  27. raise Exception('The node with ID ', str(node), ' is not contained in the target nodes of the node map.')
  28. return np.inf
  29. def get_forward_map(self):
  30. return self.__forward_map
  31. def get_backward_map(self):
  32. return self.__backward_map
  33. def add_assignment(self, i, k):
  34. if i != np.inf:
  35. if i < len(self.__forward_map):
  36. self.__forward_map[i] = k
  37. else:
  38. raise Exception('The node with ID ', str(i), ' is not contained in the source nodes of the node map.')
  39. if k != np.inf:
  40. if k < len(self.__backward_map):
  41. self.__backward_map[k] = i
  42. else:
  43. raise Exception('The node with ID ', str(k), ' is not contained in the target nodes of the node map.')
  44. def set_induced_cost(self, induced_cost):
  45. self.__induced_cost = induced_cost
  46. def induced_cost(self):
  47. return self.__induced_cost

A Python package for graph kernels, graph edit distances and graph pre-image problem.