001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.util.graphs.copy; 018 019import java.util.Collection; 020 021import net.automatalib.commons.util.mappings.Mapping; 022import net.automatalib.commons.util.mappings.Mappings; 023import net.automatalib.graphs.Graph; 024import net.automatalib.graphs.IndefiniteGraph; 025import net.automatalib.graphs.MutableGraph; 026import net.automatalib.graphs.UniversalGraph; 027import net.automatalib.graphs.UniversalIndefiniteGraph; 028import net.automatalib.util.graphs.Graphs; 029import net.automatalib.util.traversal.TraversalOrder; 030 031public class GraphCopy { 032 033 034 035 public static <N1,E1,N2,E2,NP2,EP2> 036 Mapping<N1,N2> copyPlain(Graph<N1, E1> in, 037 MutableGraph<N2, E2, NP2, EP2> out, 038 Mapping<? super N1,? extends NP2> npMapping, 039 Mapping<? super E1,? extends EP2> epMapping) { 040 PlainGraphCopy<N1, E1, N2, E2, NP2, EP2> copy = new PlainGraphCopy<>(in, out, npMapping, epMapping); 041 copy.doCopy(); 042 return copy.getNodeMapping(); 043 } 044 045 public static <N1,E1,N2,E2,NP2,EP2> 046 Mapping<N1,N2> copyPlain(UniversalGraph<N1, E1,? extends NP2, ? extends EP2> in, 047 MutableGraph<N2, E2, NP2, EP2> out) { 048 Mapping<N1,? extends NP2> npMapping = Graphs.nodeProperties(in); 049 Mapping<E1,? extends EP2> epMapping = Graphs.edgeProperties(in); 050 return copyPlain(in, out, npMapping, epMapping); 051 } 052 053 public static <N1,E1,NP1,EP1,N2,E2,NP2,EP2> 054 Mapping<N1,N2> copyUniversalPlain(UniversalGraph<N1, E1, NP1, EP1> in, 055 MutableGraph<N2, E2, NP2, EP2> out, 056 Mapping<? super NP1,? extends NP2> npConversion, 057 Mapping<? super EP1,? extends EP2> epConversion) { 058 Mapping<? super N1,? extends NP2> npMapping = Mappings.compose(Graphs.nodeProperties(in), npConversion); 059 Mapping<? super E1,? extends EP2> epMapping = Mappings.compose(Graphs.edgeProperties(in), epConversion); 060 return copyPlain(in, out, npMapping, epMapping); 061 } 062 063 public static <N1,E1,N2,E2,NP2,EP2> 064 Mapping<N1,N2> copyTraversal(IndefiniteGraph<N1,E1> in, 065 MutableGraph<N2,E2,NP2,EP2> out, 066 TraversalOrder order, 067 int limit, 068 Collection<? extends N1> initialNodes, 069 Mapping<? super N1,? extends NP2> npMapping, 070 Mapping<? super E1,? extends EP2> epMapping) { 071 TraversalGraphCopy<N1, E1, N2, E2, NP2, EP2> copy 072 = new TraversalGraphCopy<>(order, limit, in, initialNodes, out, npMapping, epMapping); 073 copy.doCopy(); 074 return copy.getNodeMapping(); 075 } 076 077 public static <N1,E1,N2,E2,NP2,EP2> 078 Mapping<N1,N2> copyTraversal(UniversalIndefiniteGraph<N1,E1,? extends NP2,? extends EP2> in, 079 MutableGraph<N2,E2,NP2,EP2> out, 080 TraversalOrder order, 081 int limit, 082 Collection<? extends N1> initialNodes) { 083 Mapping<N1,? extends NP2> npMapping = Graphs.nodeProperties(in); 084 Mapping<E1,? extends EP2> epMapping = Graphs.edgeProperties(in); 085 return copyTraversal(in, out, order, limit, initialNodes, npMapping, epMapping); 086 } 087 088 public static <N1,E1,NP1,EP1,N2,E2,NP2,EP2> 089 Mapping<N1,N2> copyUniversalTraversal(UniversalIndefiniteGraph<N1,E1,NP1,EP1> in, 090 MutableGraph<N2, E2, NP2, EP2> out, 091 TraversalOrder order, 092 int limit, 093 Collection<? extends N1> initialNodes, 094 Mapping<? super NP1,? extends NP2> npConversion, 095 Mapping<? super EP1,? extends EP2> epConversion) { 096 Mapping<? super N1,? extends NP2> npMapping = Mappings.compose(Graphs.nodeProperties(in), npConversion); 097 Mapping<? super E1,? extends EP2> epMapping = Mappings.compose(Graphs.edgeProperties(in), epConversion); 098 return copyTraversal(in, out, order, limit, initialNodes, npMapping, epMapping); 099 } 100 101}