当前位置: 首页>>代码示例>>Python>>正文


Python Graph.delete_edges方法代码示例

本文整理汇总了Python中igraph.Graph.delete_edges方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.delete_edges方法的具体用法?Python Graph.delete_edges怎么用?Python Graph.delete_edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在igraph.Graph的用法示例。


在下文中一共展示了Graph.delete_edges方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __findNegativeCut

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
    def __findNegativeCut(self,debug=False):
        """Best negative cut heuristic.

        Heuristic to find the best cut value to construct the Gamma Model (RMgamma).

        Args:
            debug (bool,optional): Show debug information. 

        Returns:
            A Heuristic object that contains all the relevant info about the heuristic.
        
        """
        
        time_total = time.time()

        # Graph and unique set construction
        time_graph_construction = time.time()

        graph_negative = Graph()
        graph_negative.add_vertices(self.__n)
        unique_negative_weights = set()
        for i in range(self.__n):
            for j in range (i+1,self.__n):
                if self.__S[i][j] <= 0:
                    graph_negative.add_edge(i,j,weight=self.__S[i][j])
                    unique_negative_weights.add(self.__S[i][j])
        time_graph_construction = time.time() - time_graph_construction

        # Sort unique weights and start heuristic to find the best cut value
        time_find_best_cut = time.time()
        
        unique_negative_weights = sorted(unique_negative_weights)

        # Test different cuts and check connected
        best_negative_cut = 0
        for newCut in unique_negative_weights:
            edges_to_delete = graph_negative.es.select(weight_lt=newCut)
            graph_negative.delete_edges(edges_to_delete)
            if graph_negative.is_connected():
                best_negative_cut = newCut
            else:
                break

        time_find_best_cut = time.time() - time_find_best_cut
        time_total = time.time() - time_total

        if debug==True:
            print ("Time Graph Construction: %f"         %(time_graph_construction))
            print ("Time Heuristic to find best cut: %f" %(time_find_best_cut))
            print ("Total Time: %f"                      %(time_total))
            print ("NEW (Best cut-): %d"                 %(best_negative_cut))

        heuristic={}
        heuristic['cut'] = best_negative_cut
        heuristic['time_total']=time_total
        heuristic['time_graph_construction']=time_graph_construction
        heuristic['time_find_best_cut']=time_find_best_cut

        return heuristic
开发者ID:LuizHNLorena,项目名称:Regnier-Problem,代码行数:61,代码来源:RegnierProblemLP.py

示例2: obtain_library_solution

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
    def obtain_library_solution(self, scc_adj_matrix, force_ip=False, force_eades=False):
        num_vertices = len(scc_adj_matrix)
        library_graph = Graph().Adjacency(scc_adj_matrix)

        if not force_eades and (num_vertices < 10 or force_ip):
            removed_edges = library_graph.feedback_arc_set(method='ip')
        else:
            removed_edges = library_graph.feedback_arc_set(method='eades')

        library_graph.delete_edges(removed_edges)
        library_graph_adj_matrix = library_graph.get_adjacency()._get_data()
        library_graph_dag_solver = DAGSolver(library_graph_adj_matrix)
        solution = library_graph_dag_solver.topological_sort()

        return solution
开发者ID:afrancis13,项目名称:MAS-Solver,代码行数:17,代码来源:final_solver.py

示例3: len

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
        # targetVertex["uid"] = gen[e[1]]
        targetVertex = e[1]
        g.add_vertex(targetVertex)
    # print adjList[e]
    g[gen[e[0]], gen[e[1]]] = adjList[e] * 5

print "graph contains ", len(g.es), "edges"
print "graph contains ", len(g.vs), "vertices"


# filterOutNoise(edge)

minDegree = 5
for e in g.es:
    if e["weight"] < 10000.0:
        g.delete_edges(e)
for x in range(8):
    print "removing:"
    for v in g.vs:
        if v.degree() < minDegree:
            g.delete_vertices(v)
    print "graph contains ", len(g.es), "edges"
    print "graph contains ", len(g.vs), "vertices"

drawPNG = True
if drawPNG:
    print "drawing begins:"
    layout = g.layout('kk')
    width, height = 5000, 5000
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)
开发者ID:abpoms,项目名称:info-overflow,代码行数:33,代码来源:simpleGraphWriter.py

示例4: Graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
from igraph import Graph

foster = Graph().LCF(90, [17, -9, 37, -37, 9, -17], 15)
foster.to_directed()

print "Is Directed? " + str(foster.is_directed())

for start in range(0, 90):
    for end in range(0, 90):
        # Don't delete this. Delete opposite direction edge
        if start + 1 == end:
            opposite_ID = foster.get_eid(end, start, True, False)
            if opposite_ID != 1:
                foster.delete_edges([opposite_ID])
        else:
            opposite_ID = foster.get_eid(end, start, True, False)
            if opposite_ID != -1:
                current_ID = foster.get_eid(start, end, True, False)
                if current_ID != -1:
                    foster.delete_edges([current_ID])

print "Number of Edges: " + str(len(foster.get_edgelist()))
print (foster.is_connected())

foster_list = foster.get_adjacency()

for sublist in foster_list:
    sublist = map(str, sublist)
    sublist_string = " ".join(sublist)
    print (sublist_string)
开发者ID:afrancis13,项目名称:MAS-Solver,代码行数:32,代码来源:fosters.py

示例5: extract_hash_tags_re

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
        keyErrorCount = keyErrorCount +1
        continue
    
    except ValueError as noJson:
        noJsonCount = noJsonCount +1
        continue

    """
    Checking if node already exists in the list of name which is also indexed like id in igraph
    so look up is fast
    Everytime a new edge/node is touched update_ts is updated to the timestamp from the tweet
    """
    text = text.lower()      
    hashtags = extract_hash_tags_re(text)  
    tweet_time = seconds_since_epoch(text.split('timestamp: ')[1].replace(')\n',''))
    g.delete_edges(get_delete_old_edges(g,'updated_ts',tweet_time))
    g.delete_vertices(get_isolated_nodes(g))
    
    if len(hashtags) > 1:
        tagSet = set(itertools.combinations(hashtags,2))
        for frm, to in tagSet:
            if frm not in g.vs['name'] and to not in g.vs['name']:
                g.add_vertex(frm,updated_ts=tweet_time)
                g.add_vertex(to,updated_ts=tweet_time)
                g.add_edge(frm,to, updated_ts = tweet_time )

            if frm not in g.vs['name'] and to in g.vs['name']:
                g.add_vertex(frm,updated_ts=tweet_time)
                g.add_edge(frm,to, updated_ts = tweet_time )
                g.vs.find(to)['updated_ts'] = tweet_time
开发者ID:xs2github,项目名称:Insight,代码行数:32,代码来源:average_degree.py

示例6: __init__

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_edges [as 别名]
class hash_tag_graph:
    """
    hash tag graph class
    """


    def __init__(self,window_duration=60,verbose=True):
        """
        Initialize the class

        :return: hash_tag_graph object
        """
        self.t_window = window_duration
        self.latest_time = 0
        self.graph = Graph()
        self.verbose=verbose


    def trim(self):
        """
        remove edges outside time window

        :return:  None
        """

        # identify edges outside window

        min_time = self.latest_time - self.t_window
        edges_to_trim = self.graph.es.select(time_lt=min_time)
        if self.verbose: print("Edges to trim: "+str(edges_to_trim))

        # remove edges outside of t_window
        self.graph.delete_edges(edges_to_trim)

        # identify vertices with 0 degree to delete
        vertices_to_trim = self.graph.vs.select(_degree=0)
        if self.verbose: print("Vertices to trim: "+str(vertices_to_trim._name_index))
        self.graph.delete_vertices(vertices_to_trim)




    def add_tweet(self,hash_tag_tuple,epoch_time):
        """

        Adds tweet to hash tag graph and updates graph such that it only contains tweets
        withing window_duration of the latest in time tweet. If tweet is outside of the window_duration
        than it is not added to the graph and nothing happens


        :return:
        """
        # Check if tweet is in order, inside the window duration, or outside
        t_diff = self.latest_time - epoch_time > self.t_window

        if t_diff <= self.t_window:
            self.latest_time = max(epoch_time,self.latest_time)

            current_vertices = self.graph.vs._name_index
            if self.verbose:
                print('Graph name index: '+str(current_vertices))
                print('Graph name index type: '+str(type(current_vertices)))

            # current vertivces will have none type when it is initilazed empty
            if current_vertices is not None:

                # Add hashtag to graph as vertex, if its already exists, nothing happens
                for hash_tag in hash_tag_tuple:
                    # only add hashtag if it isn't already in the graph
                    if hash_tag not in current_vertices:
                        if self.verbose: print("Adding Vertex: "+str(hash_tag))
                        self.graph.add_vertex(name=hash_tag)
            else:
                # Add hashtag to graph as vertex, if its already exists, nothing happens
                for hash_tag in hash_tag_tuple:
                    if self.verbose: print("Adding Vertex: "+str(hash_tag))
                    self.graph.add_vertex(name=hash_tag)



            # Add edges with associated epoch time
            for edge in combinations(hash_tag_tuple,r=2):
                if self.verbose: print('Adding Edge Pair:'+str(edge)+" Time:"+str(epoch_time))

                self.graph.add_edge(source=edge[0],target=edge[1],time=epoch_time)

            self.trim()

        # if tweet is outside of the time window than toss it
        else:
            return

        return



    def get_mean_degree(self):
        """
        Compute the average degree

#.........这里部分代码省略.........
开发者ID:Li-Erica,项目名称:Insight-Challenge,代码行数:103,代码来源:Hash_Tag_Graph.py


注:本文中的igraph.Graph.delete_edges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。