thoneyvazul@916: /* -*- mode: C++; indent-tabs-mode: nil; -*- thoneyvazul@916: * thoneyvazul@916: * This file is a part of LEMON, a generic C++ optimization library. thoneyvazul@916: * thoneyvazul@916: * Copyright (C) 2003-2010 thoneyvazul@916: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport thoneyvazul@916: * (Egervary Research Group on Combinatorial Optimization, EGRES). thoneyvazul@916: * thoneyvazul@916: * Permission to use, modify and distribute this software is granted thoneyvazul@916: * provided that this copyright notice appears in all copies. For thoneyvazul@916: * precise terms see the accompanying LICENSE file. thoneyvazul@916: * thoneyvazul@916: * This software is provided "AS IS" with no warranty of any kind, thoneyvazul@916: * express or implied, and with no claim as to its suitability for any thoneyvazul@916: * purpose. thoneyvazul@916: * thoneyvazul@916: */ thoneyvazul@916: thoneyvazul@916: #include thoneyvazul@916: thoneyvazul@916: #include "test_tools.h" thoneyvazul@916: #include thoneyvazul@916: #include thoneyvazul@916: #include thoneyvazul@916: #include thoneyvazul@916: #include thoneyvazul@916: #include thoneyvazul@916: thoneyvazul@916: using namespace lemon; thoneyvazul@916: using namespace std; thoneyvazul@916: thoneyvazul@916: char test_lgf[] = thoneyvazul@916: "@nodes\n" thoneyvazul@916: "label\n" thoneyvazul@916: "0\n" thoneyvazul@916: "1\n" thoneyvazul@916: "2\n" thoneyvazul@916: "3\n" thoneyvazul@916: "@arcs\n" thoneyvazul@916: " label capacity\n" thoneyvazul@916: "0 1 0 2\n" thoneyvazul@916: "1 0 1 2\n" thoneyvazul@916: "2 1 2 1\n" thoneyvazul@916: "2 3 3 3\n" thoneyvazul@916: "3 2 4 3\n" thoneyvazul@916: "3 1 5 5\n" thoneyvazul@916: "@attributes\n" thoneyvazul@916: "s 0\n" thoneyvazul@916: "x 1\n" thoneyvazul@916: "y 2\n" thoneyvazul@916: "z 3\n"; thoneyvazul@916: thoneyvazul@916: void checkMaxCardSearchCompile() { thoneyvazul@916: thoneyvazul@916: typedef concepts::Digraph Digraph; thoneyvazul@916: typedef int Value; thoneyvazul@916: typedef Digraph::Node Node; thoneyvazul@916: typedef Digraph::Arc Arc; thoneyvazul@916: typedef concepts::ReadMap CapMap; thoneyvazul@916: typedef concepts::ReadWriteMap CardMap; thoneyvazul@916: typedef concepts::ReadWriteMap ProcMap; thoneyvazul@916: typedef Digraph::NodeMap HeapCrossRef; thoneyvazul@916: thoneyvazul@916: Digraph g; thoneyvazul@916: Node n,s; thoneyvazul@916: CapMap cap; thoneyvazul@916: CardMap card; thoneyvazul@916: ProcMap proc; thoneyvazul@916: HeapCrossRef crossref(g); thoneyvazul@916: thoneyvazul@916: typedef MaxCardinalitySearch thoneyvazul@916: ::SetCapacityMap thoneyvazul@916: ::SetCardinalityMap thoneyvazul@916: ::SetProcessedMap thoneyvazul@916: ::SetStandardHeap > thoneyvazul@916: ::Create MaxCardType; thoneyvazul@916: thoneyvazul@916: MaxCardType maxcard(g,cap); thoneyvazul@916: const MaxCardType& const_maxcard = maxcard; thoneyvazul@916: thoneyvazul@916: const MaxCardType::Heap& heap_const = const_maxcard.heap(); thoneyvazul@916: MaxCardType::Heap& heap = const_cast(heap_const); thoneyvazul@916: maxcard.heap(heap,crossref); thoneyvazul@916: thoneyvazul@916: maxcard.capacityMap(cap).cardinalityMap(card).processedMap(proc); thoneyvazul@916: thoneyvazul@916: maxcard.init(); thoneyvazul@916: maxcard.addSource(s); thoneyvazul@916: n = maxcard.nextNode(); thoneyvazul@916: maxcard.processNextNode(); thoneyvazul@916: maxcard.start(); thoneyvazul@916: maxcard.run(s); thoneyvazul@916: maxcard.run(); thoneyvazul@916: } thoneyvazul@916: thoneyvazul@916: void checkWithIntMap( std::istringstream& input) thoneyvazul@916: { thoneyvazul@916: typedef SmartDigraph Digraph; thoneyvazul@916: typedef Digraph::Node Node; thoneyvazul@916: typedef Digraph::ArcMap CapMap; thoneyvazul@916: thoneyvazul@916: Digraph g; thoneyvazul@916: Node s,x,y,z,a; thoneyvazul@916: CapMap cap(g); thoneyvazul@916: thoneyvazul@916: DigraphReader(g,input). thoneyvazul@916: arcMap("capacity", cap). thoneyvazul@916: node("s",s). thoneyvazul@916: node("x",x). thoneyvazul@916: node("y",y). thoneyvazul@916: node("z",z). thoneyvazul@916: run(); thoneyvazul@916: thoneyvazul@916: MaxCardinalitySearch maxcard(g,cap); thoneyvazul@916: thoneyvazul@916: maxcard.init(); thoneyvazul@916: maxcard.addSource(s); thoneyvazul@916: maxcard.start(x); thoneyvazul@916: thoneyvazul@916: check(maxcard.processed(s) and !maxcard.processed(x) and thoneyvazul@916: !maxcard.processed(y), "Wrong processed()!"); thoneyvazul@916: thoneyvazul@916: a=maxcard.nextNode(); thoneyvazul@916: check(maxcard.processNextNode()==a, thoneyvazul@916: "Wrong nextNode() or processNextNode() return value!"); thoneyvazul@916: thoneyvazul@916: check(maxcard.processed(a), "Wrong processNextNode()!"); thoneyvazul@916: thoneyvazul@916: maxcard.start(); thoneyvazul@916: check(maxcard.cardinality(x)==2 and maxcard.cardinality(y)>=4, thoneyvazul@916: "Wrong cardinalities!"); thoneyvazul@916: } thoneyvazul@916: thoneyvazul@916: void checkWithConst1Map(std::istringstream &input) { thoneyvazul@916: typedef SmartDigraph Digraph; thoneyvazul@916: typedef Digraph::Node Node; thoneyvazul@916: thoneyvazul@916: Digraph g; thoneyvazul@916: Node s,x,y,z; thoneyvazul@916: thoneyvazul@916: DigraphReader(g,input). thoneyvazul@916: node("s",s). thoneyvazul@916: node("x",x). thoneyvazul@916: node("y",y). thoneyvazul@916: node("z",z). thoneyvazul@916: run(); thoneyvazul@916: thoneyvazul@916: MaxCardinalitySearch maxcard(g); thoneyvazul@916: maxcard.run(s); thoneyvazul@916: check(maxcard.cardinality(x)==1 && thoneyvazul@916: maxcard.cardinality(y)+maxcard.cardinality(z)==3, thoneyvazul@916: "Wrong cardinalities!"); thoneyvazul@916: } thoneyvazul@916: thoneyvazul@916: int main() { thoneyvazul@916: thoneyvazul@916: std::istringstream input1(test_lgf); thoneyvazul@916: checkWithIntMap(input1); thoneyvazul@916: thoneyvazul@916: std::istringstream input2(test_lgf); thoneyvazul@916: checkWithConst1Map(input2); thoneyvazul@916: }