Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new possibility in the save statement: possibility to export graphs
- Loading branch information
1 parent
bc4e8c7
commit f92e8a5
Showing
5 changed files
with
123 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 0 additions & 110 deletions
110
msi.gama.core/src/msi/gama/util/graph/writer/AvailableGraphWriters.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
msi.gama.core/src/msi/gama/util/graph/writer/GraphExporters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/******************************************************************************************************* | ||
* | ||
* msi.gama.util.graph.writer.AvailableGraphWriters.java, in plugin msi.gama.core, is part of the source code of the | ||
* GAMA modeling and simulation platform (v. 1.8.1) | ||
* | ||
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners | ||
* | ||
* Visit https://github.com/gama-platform/gama for license information and contacts. | ||
* | ||
********************************************************************************************************/ | ||
package msi.gama.util.graph.writer; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.jgrapht.nio.GraphExporter; | ||
import org.jgrapht.nio.GraphImporter; | ||
import org.jgrapht.nio.dimacs.DIMACSExporter; | ||
import org.jgrapht.nio.dimacs.DIMACSImporter; | ||
import org.jgrapht.nio.dot.DOTExporter; | ||
import org.jgrapht.nio.dot.DOTImporter; | ||
import org.jgrapht.nio.gexf.GEXFExporter; | ||
import org.jgrapht.nio.gexf.SimpleGEXFImporter; | ||
import org.jgrapht.nio.gml.GmlExporter; | ||
import org.jgrapht.nio.gml.GmlImporter; | ||
import org.jgrapht.nio.graph6.Graph6Sparse6Exporter; | ||
import org.jgrapht.nio.graph6.Graph6Sparse6Importer; | ||
import org.jgrapht.nio.graphml.GraphMLExporter; | ||
import org.jgrapht.nio.graphml.GraphMLImporter; | ||
import org.jgrapht.nio.tsplib.TSPLIBImporter; | ||
|
||
import msi.gama.runtime.GAMA; | ||
import msi.gama.runtime.exceptions.GamaRuntimeException; | ||
|
||
/** | ||
* Lists available graphs writers, independently of the underlying library. | ||
* | ||
* @author Patrick Taillandier | ||
* | ||
*/ | ||
public class GraphExporters { | ||
|
||
private static final Map<String, Class<? extends GraphExporter>> name2writer = | ||
new HashMap<String, Class<? extends GraphExporter>>() { | ||
|
||
{ | ||
put("dimacs", DIMACSExporter.class); | ||
put("dot", DOTExporter.class); | ||
put("gexf", GEXFExporter.class); | ||
put("graphml", GraphMLExporter.class); | ||
put("graph6", Graph6Sparse6Exporter.class); | ||
put("gml", GmlExporter.class); | ||
} | ||
}; | ||
|
||
public static Set<String> getAvailableWriters() { | ||
return name2writer.keySet(); | ||
} | ||
|
||
private static Map<String, GraphExporter> name2singleton = new HashMap<>(); | ||
|
||
public static GraphExporter getGraphWriter(final String name) { | ||
GraphExporter res = name2singleton.get(name); | ||
|
||
if ( res == null ) { | ||
// no singleton created | ||
Class<? extends GraphExporter> clazz = name2writer.get(name); | ||
if ( clazz == null ) { throw GamaRuntimeException.error( | ||
"unknown exporter name: " + name + "; please choose one of " + getAvailableWriters().toString(), | ||
GAMA.getRuntimeScope()); } | ||
Constructor<?> ctor; | ||
try { | ||
ctor = clazz.getConstructor(); | ||
res = (GraphExporter) ctor.newInstance(); | ||
name2singleton.put(name, res); | ||
return res; | ||
} catch (NoSuchMethodException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} catch (SecurityException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} catch (IllegalArgumentException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} catch (InvocationTargetException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} catch (InstantiationException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} catch (IllegalAccessException e) { | ||
throw GamaRuntimeException.create(e, GAMA.getRuntimeScope()); | ||
} | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters