lemon/bits/extendable_graph_extender.h
author deba
Mon, 13 Feb 2006 09:42:53 +0000
changeset 1967 5d81ba873b90
parent 1910 f95eea8c34b0
permissions -rw-r--r--
New algorithm:
MaxCardinalitySearch
MinimalCut // in UGraph
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_EXTENDABLE_GRAPH_EXTENDER_H
    20 #define LEMON_EXTENDABLE_GRAPH_EXTENDER_H
    21 
    22 namespace lemon {
    23 
    24   template <typename _Base> 
    25   class ExtendableGraphExtender : public _Base {
    26   public:
    27 
    28     typedef ExtendableGraphExtender Graph;
    29     typedef _Base Parent;
    30 
    31     typedef typename Parent::Node Node;
    32     typedef typename Parent::Edge Edge;
    33 
    34     Node addNode() {
    35       Node node = Parent::addNode();
    36       Parent::getNotifier(Node()).add(node);
    37       return node;
    38     }
    39     
    40     Edge addEdge(const Node& from, const Node& to) {
    41       Edge edge = Parent::addEdge(from, to);
    42       Parent::getNotifier(Edge()).add(edge);
    43       return edge;
    44     }
    45 
    46   };
    47 
    48   template <typename _Base> 
    49   class ExtendableEdgeSetExtender : public _Base {
    50   public:
    51 
    52     typedef ExtendableEdgeSetExtender Graph;
    53     typedef _Base Parent;
    54 
    55     typedef typename Parent::Edge Edge;
    56     typedef typename Parent::Node Node;
    57 
    58     Edge addEdge(const Node& from, const Node& to) {
    59       Edge edge = Parent::addEdge(from, to);
    60       Parent::getNotifier(Edge()).add(edge);
    61       return edge;
    62     }
    63 
    64   };
    65 
    66   template <typename _Base> 
    67   class ExtendableUGraphExtender : public _Base {
    68   public:
    69 
    70     typedef ExtendableUGraphExtender Graph;
    71     typedef _Base Parent;
    72 
    73     typedef typename Parent::Node Node;
    74     typedef typename Parent::Edge Edge;
    75     typedef typename Parent::UEdge UEdge;
    76 
    77     Node addNode() {
    78       Node node = Parent::addNode();
    79       Parent::getNotifier(Node()).add(node);
    80       return node;
    81     }
    82 
    83     UEdge addEdge(const Node& from, const Node& to) {
    84       UEdge uedge = Parent::addEdge(from, to);
    85       Parent::getNotifier(UEdge()).add(uedge);
    86 
    87       std::vector<Edge> edges;
    88       edges.push_back(Parent::direct(uedge, true));
    89       edges.push_back(Parent::direct(uedge, false));
    90       Parent::getNotifier(Edge()).add(edges);
    91 
    92       return uedge;
    93     }
    94 
    95   };
    96 
    97   template <typename _Base> 
    98   class ExtendableUEdgeSetExtender : public _Base {
    99   public:
   100 
   101     typedef ExtendableUEdgeSetExtender Graph;
   102     typedef _Base Parent;
   103 
   104     typedef typename Parent::Node Node;
   105     typedef typename Parent::Edge Edge;
   106     typedef typename Parent::UEdge UEdge;
   107 
   108     UEdge addEdge(const Node& from, const Node& to) {
   109       UEdge uedge = Parent::addEdge(from, to);
   110       Parent::getNotifier(UEdge()).add(uedge);
   111 
   112       std::vector<Edge> edges;
   113       edges.push_back(Parent::direct(uedge, true));
   114       edges.push_back(Parent::direct(uedge, false));
   115       Parent::getNotifier(Edge()).add(edges);
   116 
   117       return uedge;
   118     }
   119 
   120   };
   121 
   122 
   123   template <typename _Base>
   124   class ExtendableBpUGraphExtender : public _Base {
   125   public:
   126 
   127     typedef _Base Parent;
   128     typedef ExtendableBpUGraphExtender Graph;
   129   
   130     typedef typename Parent::Node Node;
   131     typedef typename Parent::BNode BNode;
   132     typedef typename Parent::ANode ANode;
   133     typedef typename Parent::Edge Edge;
   134     typedef typename Parent::UEdge UEdge;
   135   
   136     Node addANode() {
   137       Node node = Parent::addANode();
   138       Parent::getNotifier(ANode()).add(node);
   139       Parent::getNotifier(Node()).add(node);
   140       return node;
   141     }
   142 
   143     Node addBNode() {
   144       Node node = Parent::addBNode();
   145       Parent::getNotifier(BNode()).add(node);
   146       Parent::getNotifier(Node()).add(node);
   147       return node;
   148     }
   149   
   150     UEdge addEdge(const Node& source, const Node& target) {
   151       UEdge uedge = Parent::addEdge(source, target);
   152       Parent::getNotifier(UEdge()).add(uedge);
   153     
   154       std::vector<Edge> edges;
   155       edges.push_back(Parent::direct(uedge, true));
   156       edges.push_back(Parent::direct(uedge, false));
   157       Parent::getNotifier(Edge()).add(edges);
   158     
   159       return uedge;
   160     }
   161 
   162   };
   163 
   164 }
   165 
   166 #endif