forked from FFrankyy/FINDER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.pyx
54 lines (47 loc) · 2.26 KB
/
utils.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from cython.operator import dereference as deref
from libcpp.memory cimport shared_ptr
import numpy as np
import graph
from graph cimport Graph
import gc
from libc.stdlib cimport free
cdef class py_Utils:
cdef shared_ptr[Utils] inner_Utils
cdef shared_ptr[Graph] inner_Graph
def __cinit__(self):
self.inner_Utils = shared_ptr[Utils](new Utils())
# def __dealloc__(self):
# if self.inner_Utils != NULL:
# self.inner_Utils.reset()
# gc.collect()
def getRobustness(self,_g,solution):
self.inner_Graph =shared_ptr[Graph](new Graph())
deref(self.inner_Graph).num_nodes = _g.num_nodes
deref(self.inner_Graph).num_edges = _g.num_edges
deref(self.inner_Graph).edge_list = _g.edge_list
deref(self.inner_Graph).adj_list = _g.adj_list
return deref(self.inner_Utils).getRobustness(self.inner_Graph,solution)
def reInsert(self,_g,solution,allVex,int decreaseStrategyID,int reinsertEachStep):
self.inner_Graph =shared_ptr[Graph](new Graph())
deref(self.inner_Graph).num_nodes = _g.num_nodes
deref(self.inner_Graph).num_edges = _g.num_edges
deref(self.inner_Graph).edge_list = _g.edge_list
deref(self.inner_Graph).adj_list = _g.adj_list
return deref(self.inner_Utils).reInsert(self.inner_Graph,solution,allVex,decreaseStrategyID,reinsertEachStep)
def getMxWccSz(self, _g):
self.inner_Graph =shared_ptr[Graph](new Graph())
deref(self.inner_Graph).num_nodes = _g.num_nodes
deref(self.inner_Graph).num_edges = _g.num_edges
deref(self.inner_Graph).edge_list = _g.edge_list
deref(self.inner_Graph).adj_list = _g.adj_list
return deref(self.inner_Utils).getMxWccSz(self.inner_Graph)
def Betweenness(self,_g):
self.inner_Graph =shared_ptr[Graph](new Graph())
deref(self.inner_Graph).num_nodes = _g.num_nodes
deref(self.inner_Graph).num_edges = _g.num_edges
deref(self.inner_Graph).edge_list = _g.edge_list
deref(self.inner_Graph).adj_list = _g.adj_list
return deref(self.inner_Utils).Betweenness(self.inner_Graph)
@property
def MaxWccSzList(self):
return deref(self.inner_Utils).MaxWccSzList