create GraphHopper API for Desktop - java

I would like to use GraphHopper to create my own API for routing. I have taken a look into the GraphHopper.java to create my own class. I put a OSM file into the API I get a directory with edges, nodes etc. This seems to work well.
My question is, how can I load this data, so that I can call the route-Method? I try to understand the GraphHopper.java class, but my example does not work. I try to load the graph with
GHDirectory l_dir = new GHDirectory( m_graphlocation.getAbsolutePath(), DAType.RAM);
m_graph = new LevelGraphStorage( l_dir, m_EncodingManager );
Do I need the OSM file again for routing or can I use the directory with edges and nodes only?
IMHO I need a call
OSMReader l_reader = new OSMReader( l_graph, CConfiguration.getInstance().get().ExpectedCapacity).setWorkerThreads(-1).setEncodingManager(m_EncodingManager).setWayPointMaxDistance(CConfiguration.getInstance().get().WaypointMaxDistance).setEnableInstructions(false);
l_reader.doOSM2Graph(p_osm);
l_graph.optimize();
to create my graph, so is it correct to create my GraphHopperAPI class, overload the methods and on load the data with the code above and can call route?
Thanks a lot
Phil

You only need the OSM import once. In the GraphHopper class a new storage is instantiated and then loadExisting is called. If that fails you know that you need to import the OSM file and create new graphhopper files. E.g. out of my head it should be similar to this:
g = new LevelGraphStorage(dir, encodingManager);
if(!g.loadExisting()) {
reader = new OSMReader(g).setLotsOfThings
reader.doOSM2Graph..
}
The problem is that if you disable CH you can just use the GraphHopperStorage. Then you need the LocationIndex properly loaded or created at the correct place etc. Have a look into the existing unit tests where I also just use the raw stuff instead of the GraphHopper wrapper class.
But why not just create a subclass of GraphHopper and use the existing hooks (postProcessing, createWeighting, ...) to customize it to your needs?

I use this code:
GHDirectory l_dir = new GHDirectory( l_graphlocation.getAbsolutePath(), DAType.RAM_STORE);
m_graph = new LevelGraphStorage( l_dir, m_EncodingManager );
m_graph.setSegmentSize( CConfiguration.getInstance().get().SegmentSize );
if (!m_graph.loadExisting())
{
File l_osm = this.downloadOSMData();
OSMReader l_reader = new OSMReader( m_graph, CConfiguration.getInstance().get().ExpectedCapacity).setWorkerThreads(-1).setEncodingManager(m_EncodingManager).setWayPointMaxDistance(CConfiguration.getInstance().get().WaypointMaxDistance).setEnableInstructions(false);
l_reader.doOSM2Graph(l_osm);
m_graph.optimize();
m_graph.flush();
// do I need this?
PrepareRoutingSubnetworks l_preparation = new PrepareRoutingSubnetworks(m_graph, m_EncodingManager);
l_preparation.setMinNetworkSize( CConfiguration.getInstance().get().MinNetworkSize );
l_preparation.doWork();
}
// is this correct?
m_index = new LocationIndexTree(m_graph, l_dir);
m_index.setResolution( CConfiguration.getInstance().get().IndexResolution );
m_index.setSearchRegion(true);
if (!m_index.loadExisting())
throw new IOException("unable to load graph index file");
// does not work without the graph
m_graphhopper = new GraphHopper().setEncodingManager(m_EncodingManager).forDesktop();
I cannot create a working structure. I have taken a look into the test examples eg https://github.com/graphhopper/graphhopper/blob/master/core/src/test/java/com/graphhopper/GraphHopperAPITest.java but the loadGraph method cannot be called outside the package.
I would like to create a correct graph database from the OSM file, this seems to be working. Than I would like to finde the closest edge to a geo location with:
m_index.findClosest( p_position.getLatitude(), p_position.getLongitude(), EdgeFilter.ALL_EDGES );
but this returns a null pointer exception, so imho my index should be wrong. How can I create a correct working index?
After this I would like to create a fast / shortest route through the graph with
GHRequest l_request = new GHRequest( p_start.getLatitude(), p_start.getLongitude(), p_end.getLatitude(), p_end.getLongitude() );
l_request.setAlgorithm( CConfiguration.getInstance().get().RoutingAlgorithm );
return m_graphhopper.route(l_request);
but I cannot create a working graphhopper instance for call the route-method.

Related

Not able to reference Java class from my report in BIRT

I am very new to BIRT. I am wokring on a BIRT project where I am trying to reference Java class inside script 'open' section but am unable to do so.
I do not get any errors but I am not able to see any data in my dataset preview.
Script - open
count = 0;
// create instance of
// the GetStockHistory class
gsh = new Packages.de.vogella.birt.stocks.daomock.StockDaoMock(); //cause of error somehow
//Load the List
stock = gsh.getStockValues("Java");
Script-Fetch
if(count < stock.size()){
row["columnDate"] = stock.get(count).getDate();
row["columnOpen"] = stock.get(count).getOpen();
row["columnHigh"] = stock.get(count).getHigh();
row["columnLow"] = stock.get(count).getLow();
row["columnClose"] = stock.get(count).getClose();
row["columnVolume"] = stock.get(count).getVolume();
count++;
return true;
}
return false;
StockDaoMock is a class which returns a dummy list of values.
Referring this blog BIRT sample app
Can anyone please help me here and let me know what am I doing wrong ?
Why can't I see any data in preview dataset. Is there a specific way in which I need to make reference to java classes because I am sure the error is somewhere in that part only. If I remove the reference part and just hardcode a string, then it is working fine and I can see it in the preview. Things mess up as soon as I refer a java class by importing it.
BIRT-4.8
EDIT---
even this inside my Script 'open' doesn't work
importPackage(Packages.de.vogella.birt.stocks.daomock);
gsh = new StockDaoMock();
BIRT does not use the java sources directly. You have to generate a JAR from your classes and add that JAR to your BIRT class path (Window / Preferences / Report Design / Classpath).

IBM RTC API - Adding files to change sets

Basically I'm experimenting with the IBM Rational Team Concert Plain Java Client API, and I'm stuck at adding operations to change sets.
I create a new change set, retrieve the Operation factory and then I'd like to add a new file from the local machine file system (might be a new file of a project).
val changeSetHandle = workspaceConnection.createChangeSet(component, null)
val operationFactory = workspaceConnection.configurationOpFactory()
val saveOperation = operationFactory.save(...)
I do not understand how to to obtain an IVersionable handle to submit to the save() method.
You can refer to this thread which shows an example of IVersionable:
// Create a new file and give it some content
IFileItem file = (IFileItem) IFileItem.ITEM_TYPE.createItem();
file.setName("file.txt");
file.setParent(projectFolder);
// Create file content.
IFileContentManager contentManager = FileSystemCore.getContentManager(repository);
IFileContent fileContent = contentManager.storeContent(
"UTF-8",
FileLineDelimiter.LINE_DELIMITER_LF,
new VersionedContentManagerByteArrayInputStreamPovider(BYTE_ARRAY),
null,
null);
file.setContent(fileContent);
file.setContentType(IFileItem.CONTENT_TYPE_TEXT);
file.setFileTimestamp(new Date());
workspaceConnection.configurationOpFactory().save(file);
However, this is not enough:
IConfigurationOpFactory is used to update a repository workspace by adding changes to a change set.
The usage pattern is to get a workspace connection, create a bunch of save operations, then run IWorkspaceConnection#commit() on those ops.
Calling save() without committing the change drops the op onto the stack for the garbage collector to gobble up. ;)

StaxItemReader to read and print the values

I am learning spring batch now. I wanted to use StaxEventItemReaderto read xml file
So I just tried using it in standalone java file in java perspective with all necessary spring jars.
I want to know how can I ensure whether it has read the values and what values it has read . In short I want to print the read values in console . How can I do it in standalone java file?
Code as follows:
main(){
StaxEventItemReader<Student> xmlFileReader = new StaxEventItemReader<Student>();
xmlFileReader.setResource(new ClassPathResource("/Student.xml"));
xmlFileReader.setFragmentRootElementName("Marks");
Jaxb2Marshaller medicareMarshaller = new Jaxb2Marshaller();
medicareMarshaller.setClassesToBeBound(Student.class);
xmlFileReader.setUnmarshaller(medicareMarshaller);
System.out.println(xmlFileReader. ?);
}
Please help me in knowing how to print the read values. I apologise if my content is not clear. Thanks in Advance.
Try my adapted code below.
Generally, if you want to test SpringBatch components without having them instantiated as Spring-Beans (-> by calling der Constructor directly), you should call the "afterPropertiesSet()" method, after you have called all your set-Methods.
Next, depending on the reader/writers you want to test directly, you have to call reader.open(new ExecutionContext()).
After that, you can call the read()-method, which should then return item after item.
main(){
StaxEventItemReader<Student> xmlFileReader = new StaxEventItemReader<Student>();
xmlFileReader.setResource(new ClassPathResource("/Student.xml"));
xmlFileReader.setFragmentRootElementName("Marks");
Jaxb2Marshaller medicareMarshaller = new Jaxb2Marshaller();
medicareMarshaller.setClassesToBeBound(Student.class);
xmlFileReader.setUnmarshaller(medicareMarshaller);
xmlFileReader.afterPropertiesSet(); // in the case of StaxEventItemReader not really necessary
xmlFileReader.open(new ExecutionContext()); // does some initialisation, so you need to call it
Studen student = null;
while(student = xmlFileReader.read() != null) {
System.out.println(student...);
}
xmlFileReader.close();

What is the filepath that FANNJ (FANN in Java) constructor is expecting?

I am new to working with java. I wanted to know the requisites and the procedure to use the FANN-1.1 tool library in java to train a set of data.
The code given in https://code.google.com/p/fannj/ is
Fann fann = new Fann( "/path/to/file" );
float[] inputs = new float[]{ -1, 1 };
float[] outputs = fann.run( inputs );
fann.close();
here what is /path/to/file
According to fann source codes it seems to be a pointer to a configuration file. You probably should use "fann_set_user_data" in your existing ANN in C. It would create a file retrievable by "fann_get_user_data" function and also would be what fannj example is expecting. Fannj implementation has many other function interfaces, so, it is only an example.
Sources:
http://leenissen.dk/fann/html/files/fann-h.html#fann_set_user_data
https://github.com/krenfro/fannj/blob/master/src/main/java/com/googlecode/fannj/Fann.java

Calling a Java Web Service from a .Net Project - Handling arrays

I am trying to call some web services written in Java from my asp.net code. I don't know Java.
There are several methods each with multiple properties. These methods are then passed to one controlling method. The problem occurs with how to handle arrays. I cannot seem to get the syntax quite right.
For example, there can be from 1 to n locations. Each location has multiple properties.
I can build one location ok. But how do I build an array of locations? I tried several approaches. Here is the closest I’ve gotten. It complies but crashes on the third to the last line below. I’ve removed the code that is not relevant to explaining the problem.
The error says: Object reference not set to an instance of an object.
WebReferenceMERegistration.getMERegistration _myMERegistration =
new WebReferenceMERegistration.getMERegistration();
WebReferenceMERegistration.Locations _myLocation =
new WebReferenceMERegistration.Locations();
WebReferenceMERegistration.Locations[] _myLocations = null;
_myLocation.AddressLine1 = txtEmployerAddress1.Text;
_myLocation.AddressLine2 = txtEmployerAddress2.Text;
// more properties set here
_myLocations[0] = _myLocation;
_myMERegistration.Locations = _myLocations;
_Results = _myRegistrationService.getMERegistration(_myMERegistration);
int length = ...;
WebReferenceMERegistration.Locations[] _myLocations =
new WebReferenceMERegistration.Locations[length];

Categories

Resources