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.h 4.3 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include "minddata/dataset/engine/gnn/feature.h"
  22. #include "minddata/dataset/util/status.h"
  23. namespace mindspore {
  24. namespace dataset {
  25. namespace gnn {
  26. using NodeType = int8_t;
  27. using NodeIdType = int32_t;
  28. using WeightType = float;
  29. using EdgeIdType = int32_t;
  30. constexpr NodeIdType kDefaultNodeId = -1;
  31. class Edge;
  32. class Node {
  33. public:
  34. // Constructor
  35. // @param NodeIdType id - node id
  36. // @param NodeType type - node type
  37. // @param WeightType type - node weight
  38. Node(NodeIdType id, NodeType type, WeightType weight) : id_(id), type_(type), weight_(weight) {}
  39. virtual ~Node() = default;
  40. // @return NodeIdType - Returned node id
  41. NodeIdType id() const { return id_; }
  42. // @return NodeIdType - Returned node type
  43. NodeType type() const { return type_; }
  44. // @return WeightType - Returned node weight
  45. WeightType weight() const { return weight_; }
  46. // Get the feature of a node
  47. // @param FeatureType feature_type - type of feature
  48. // @param std::shared_ptr<Feature> *out_feature - Returned feature
  49. // @return Status The status code returned
  50. virtual Status GetFeatures(FeatureType feature_type, std::shared_ptr<Feature> *out_feature) = 0;
  51. // Get the all neighbors of a node
  52. // @param NodeType neighbor_type - type of neighbor
  53. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  54. // @return Status The status code returned
  55. virtual Status GetAllNeighbors(NodeType neighbor_type, std::vector<NodeIdType> *out_neighbors,
  56. bool exclude_itself = false) = 0;
  57. // Get the sampled neighbors of a node
  58. // @param NodeType neighbor_type - type of neighbor
  59. // @param int32_t samples_num - Number of neighbors to be acquired
  60. // @param SamplingStrategy strategy - Sampling strategy
  61. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  62. // @return Status The status code returned
  63. virtual Status GetSampledNeighbors(NodeType neighbor_type, int32_t samples_num, SamplingStrategy strategy,
  64. std::vector<NodeIdType> *out_neighbors) = 0;
  65. // Add neighbor of node
  66. // @param std::shared_ptr<Node> node -
  67. // @return Status The status code returned
  68. virtual Status AddNeighbor(const std::shared_ptr<Node> &node, const WeightType &weight) = 0;
  69. // Add adjacent node and relative edge for source node
  70. // @param std::shared_ptr<Node> node - the node to be inserted into adjacent table
  71. // @param std::shared_ptr<Edge> edge - the edge related to the adjacent node of source node
  72. // @return Status - The status code that indicate the result of function execution
  73. virtual Status AddAdjacent(const std::shared_ptr<Node> &node, const std::shared_ptr<Edge> &edge) = 0;
  74. // Get relative connecting edge of adjacent node by node id
  75. // @param NodeIdType - The id of adjacent node to be processed
  76. // @param std::shared_ptr<EdgeIdType> - The id of relative connecting edge
  77. // @return Status - The status code that indicate the result of function execution
  78. virtual Status GetEdgeByAdjNodeId(const NodeIdType &adj_node_id, EdgeIdType **out_edge_id) = 0;
  79. // Update feature of node
  80. // @param std::shared_ptr<Feature> feature -
  81. // @return Status The status code returned
  82. virtual Status UpdateFeature(const std::shared_ptr<Feature> &feature) = 0;
  83. protected:
  84. NodeIdType id_;
  85. NodeType type_;
  86. WeightType weight_;
  87. };
  88. } // namespace gnn
  89. } // namespace dataset
  90. } // namespace mindspore
  91. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_