JGrapht: Generate subgraphs with DirectedSubgraph.java class - jgrapht

I use jgrapht. I will generate subgraphs.
I think jgrapht-0.8.2/jgrapht-0.8.2/src/org/jgrapht/graph/DirectedSubgraph.java is useful for this purpose. But I could not find how can I use this class? Can you help me ?
For example: jgrapht-0.8.2/jgrapht-0.8.2/src/org/jgrapht/demo/HelloJGraphT.java
A directed graph constructor is used like that in HelloJGraphT.java class
DirectedGraph<String, DefaultEdge> g =
new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);

if you want to create your new sub graph, you have to write this code:
DirectedSubgraph<String, DefaultEdge> YouSubGraph = new DirectedSubgraph<String, DefaultEdge>(arg0, arg1, arg2)
Where arg0, is your main graph, arg1 is the set of your vertex in your sub graph, and arg2 is the set of your edges in your sub graph.
You can obtain the edged set using:
Set<DefaultEdge> YourEdges = YouSubGraph.edgeSet();
I think that you could obtain the vertex on the same way.
Sorry for mi English I hope it helps you.

Related

How to use CSVImporter and create vertex supplier

I can't find any documentation on how to use the CSVImporter (1.5.0). I have a very simple csv file with integers that I'm trying to import using the following code:
Graph<String, DefaultEdge> wpCategories = new DirectedMultigraph(DefaultEdge.class);
CSVImporter<String, DefaultEdge> importer = new CSVImporter(CSVFormat.EDGE_LIST);
importer.importGraph(wpCategories, new File("hypernymGraphWithEntities_WP1-small.csv"));
I just get a "The graph contains no vertex supplier" exception. How do I create a vertex supplier?
A JGraphT graph consists of vertex and edge objects. When importing a graph from a text file, the importer must somehow create vertex objects for every vertex it encounters in the text file. These objects must be of the same type you defined in the graph. To generate these objects, JGraphT uses vertex suppliers.
Various examples of how to use the CSV importer can be found in the corresponding test class CSVImporterTest.
There are two different ways to create a graph with a vertex supplier. Either you use the GraphTypeBuilder, or you use one of the graph constructors. Here's an example for a directed graph.
//Builder
Graph<String,DefaultEdge> g1 = GraphTypeBuilder.directed().allowingMultipleEdges(false).allowingSelfLoops(false).weighted(false).edgeClass(DefaultEdge.class).vertexSupplier(SupplierUtil.createStringSupplier(1)).buildGraph();
//Constructor
Graph<String,DefaultEdge> g2 = new DefaultDirectedGraph(SupplierUtil.createStringSupplier(1),SupplierUtil.DEFAULT_EDGE_SUPPLIER,false);
So applied to your example this would give:
Graph<String, DefaultEdge> wpCategories = new DirectedMultigraph(SupplierUtil.createStringSupplier(1),SupplierUtil.DEFAULT_EDGE_SUPPLIER,false);
CSVImporter<String, DefaultEdge> importer = new CSVImporter(CSVFormat.EDGE_LIST);
importer.importGraph(wpCategories, new File("hypernymGraphWithEntities_WP1-small.csv"));
Note that, as an alternative to the vertex supplier, you could also use the setVertexFactory function in the CSVImporter class. Again, using your code:
Graph<String, DefaultEdge> wpCategories = new DirectedMultigraph(DefaultEdge.class);
CSVImporter<String, DefaultEdge> importer = new CSVImporter(CSVFormat.EDGE_LIST);
Function<String, String> vertexFactory = x -> x;
importer.setVertexFactory(vertexFactory);
importer.importGraph(wpCategories, new File("hypernymGraphWithEntities_WP1-small.csv"));
Disclaimer: In absence of data, the above code isn't tested.

Dynamically generate public static

I pass a string from VVVV to Unity via UDP, which is made up of multiple float groups, each one defined by a Char at the beginning, and an "!" at the end.
K0.0322 2.1062 4.2102 49.9711 43.2255!V44.7385 47.2003 49.8143 49.4658 4.1806 12.6100 6.2053!C49.9437 16.4352
I want to dynamically generate arrays with the content of each group
float[] k = {0.0322, 2.1062.........};
float[] v = {44.7385, 47.2003........};
and make them accessible for other unity scripts as public static.
Is this possible?
These public statics have to be initialized at the beginning of the script, so if they are generated dynamically they won't exist at the start.
I think maybe you can try using list
Public static List<float> newlist= new List<float>❨❩;

Creating & Setting a Map into context through SpringEl

As SpringEl doc. indicates, there is el syntax for creating a list which then allows me setting it into the context as below:
List numbers = (List) parser.parseExpression("map['innermap']['newProperty']={1,2,3,4}").getValue(context);
However, I am not able to find a way of doing the same thing for Map nor I can find it in the document.
Is there a short hand way of creating a map and then setting it to context? if not, how can we go about it.
If possible a code snippet will be helpful.
Thanks in advance.
It's now possible (since 4.1, I think):
{key:value, key:value}
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-inline-maps
No, it isn't possible yet: https://jira.spring.io/browse/SPR-9472
But you can do it with some util method, which should be registered as SpEL-function:
parser.parseExpression("#inlineMap('key1: value1, key2:' + value2)");
Where you have to parse the String arg to the Map.
UPDATE
Please, read this paragraph: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-ref-functions.
From big height it should be like this:
public abstract class StringUtils {
public static Map<String, Object> inlineMap(String input) {
// Here is a code to parse 'input' string and build a Map
}
}
context.registerFunction("inlineMap",
StringUtils.class.getDeclaredMethod("inlineMap", new Class[] { String.class }));
parser.parseExpression("#inlineMap('key1: value1, key2:' + value2)")
.getValue(context, rootObject);

Dapper Correct Object / Aggregate Mapping

I have recently started evaluating Dapper as a potential replacement for EF, since I was not too pleased with the SQL that was being generated and wanted more control over it. I have a question regarding mapping a complex object in my domain model. Let's say I have an object called Provider, Provider can contain several properties of type IEnumerable that should only be accessed by going through the parent provider object (i.e. aggregate root). I have seen similar posts that have explained using the QueryMultiple and a Map extension method but was wondering how if I wanted to write a method that would bring back the entire object graph eager loaded, if Dapper would be able to do this in one fell swoop or if it needed to be done piece-meal. As an example lets say that my object looked something like the following:
public AggregateRoot
{
public int Id {get;set;}
...//simple properties
public IEnumerable<Foo> Foos
public IEnumerable<Bar> Bars
public IEnumerable<FooBar> FooBars
public SomeOtherEntity Entity
...
}
Is there a straightforward way of populating the entire object graph using Dapper?
I have a similar situation. I made my sql return flat, so that all the sub objects come back. Then I use the Query<> to map the full set. I'm not sure how big your sets are.
So something like this:
var cnn = sqlconnection();
var results = cnn.Query<AggregateRoot,Foo,Bars,FooBar,someOtherEntity,AggregateRoot>("sqlsomething"
(ar,f,b,fb,soe)=>{
ar.Foo = f;
ar.Bars = b;
ar.FooBar = fb;
ar.someotherentity = soe;
return ar;
},.....,spliton:"").FirstOrDefault();
So the last object in the Query tag is the return object. For the SplitOn, you have to think of the return as a flat array that the mapping will run though. You would pick the first return value for each new object so that the new mapping would start there.
example:
select ID,fooid, foo1,foo2,BarName,barsomething,foobarid foobaritem1,foobaritem2 from blah
The spliton would be "ID,fooid,BarName,foobarid". As it ran over the return set, it will map the properties that it can find in each object.
I hope that this helps, and that your return set is not too big to return flat.

How to use Property Let for Arrays?

I am very new to VBS, but I am not able to implement even the simplest things, as it seems. I want to have a class which holds an array in a private member. Since I want to "inject" the array I tried to implement a "setter-method" using the Let functionality.
Class CPhase
Private m_AllowedTasks()
Public Property Let AllowedTasks(p_AllowedTasks)
m_AllowedTasks = p_AllowedTasks
End Property
Private Sub Class_Initialize()
ReDim m_AllowedTasks(0)
End Sub
End Class
This class is used as follows:
Dim allowed
allowed = Array("task1", "task2")
Dim phase
Set phase = New CPhase
phase.AllowedTasks = allowed
This results in a "Microsoft VBScript runtime error (...) : Type mismatch" in the Let-method. I also tried using different combinations of "ByVal", "ByRef", but since having absolutely no experience with VBS I couldn't find a solution. So what am I doing wrong?
Any hints or links to helpful ressources are very appreciated!
Thanks!
The culprit is
Private m_AllowedTasks()
which creates an abomination - a fixed array of no size. Just remove the ().
Private m_AllowedTasks
to create an (empty) Variant that may be set=let to an useful (redim-able) array.

Resources