title: Add weight to a relationship using neo4j embedded java api
body: <p>I would like to add a weight to a relationship using Embedded Neo4j Java API.</p>
  
  <p>For example : <code>A</code> knows <code>B</code> very well so their relationship should be weighted <code>5</code>. On the other hand, <code>A</code> knows <code>C</code> very little so their relationship should be weighted <code>1</code>.</p>
  
  <p>How can I do that?</p>
  
  <p>PS : I have already tried the example here : <a href="http://neo4j.com/docs/stable/tutorials-java-embedded-graph-algo.html" rel="nofollow noreferrer">http://neo4j.com/docs/stable/tutorials-java-embedded-graph-algo.html</a> but it doesn't recognize th functions <code>createNode( "name", "A", "x", 0d, "y", 0d )</code> and <code>createRelationship( nodeA, nodeC, "length", 2d )</code>.</p>
  
  <p>This is the code :</p>
  
  <pre><code>package com.neo4j.test.test1;
  
  import org.neo4j.graphalgo.CommonEvaluators;
  import org.neo4j.graphalgo.EstimateEvaluator;
  import org.neo4j.graphalgo.GraphAlgoFactory;
  import org.neo4j.graphalgo.PathFinder;
  import org.neo4j.graphalgo.WeightedPath;
  import org.neo4j.graphdb.GraphDatabaseService;
  import org.neo4j.graphdb.Node;
  import org.neo4j.graphdb.PathExpanders;
  import org.neo4j.graphdb.Relationship;
  import org.neo4j.graphdb.Transaction;
  import org.neo4j.graphdb.factory.GraphDatabaseFactory;
  
  import com.neo4j.test.labels.NodeLabels;
  import com.neo4j.test.labels.TypeRelation;
  
  public class Test1 {
  
      public static void main(String[] args) {
  
          GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
          GraphDatabaseService db = dbFactory.newEmbeddedDatabase("C:\\Zakaria\\NeoTests\\Test2");
  
          try (Transaction tx = db.beginTx()) {
  
              Node nodeA = createNode( "name", "A", "x", 0d, "y", 0d );
              Node nodeB = createNode( "name", "B", "x", 7d, "y", 0d );
              Node nodeC = createNode( "name", "C", "x", 2d, "y", 1d );
              Relationship relAB = createRelationship( nodeA, nodeC, "length", 2d );
              Relationship relBC = createRelationship( nodeC, nodeB, "length", 3d );
              Relationship relAC = createRelationship( nodeA, nodeB, "length", 10d );
  
              EstimateEvaluator&lt;Double&gt; estimateEvaluator = new EstimateEvaluator&lt;Double&gt;()
              {
                  @Override
                  public Double getCost( final Node node, final Node goal )
                  {
                      double dx = (Double) node.getProperty( "x" ) - (Double) goal.getProperty( "x" );
                      double dy = (Double) node.getProperty( "y" ) - (Double) goal.getProperty( "y" );
                      double result = Math.sqrt( Math.pow( dx, 2 ) + Math.pow( dy, 2 ) );
                      return result;
                  }
              };
              PathFinder&lt;WeightedPath&gt; astar = GraphAlgoFactory.aStar(
                      PathExpanders.allTypesAndDirections(),
                      CommonEvaluators.doubleCostEvaluator( "length" ), estimateEvaluator );
              WeightedPath path = astar.findSinglePath( nodeA, nodeB );
  
              tx.success();
  
          }
  
          System.out.println("Done!");
  
      }
  
  }
  </code></pre>
  
  <p>It should give this result :</p>
  
  <p><img src="https://i.stack.imgur.com/1DY9z.png" alt="enter image description here"></p>
  
  <p>It says that these following functions are not defined :</p>
  
  <pre><code>Node nodeA = createNode( "name", "A", "x", 0d, "y", 0d );
  Node nodeB = createNode( "name", "B", "x", 7d, "y", 0d );
  Node nodeC = createNode( "name", "C", "x", 2d, "y", 1d );
  Relationship relAB = createRelationship( nodeA, nodeC, "length", 2d );
  Relationship relBC = createRelationship( nodeC, nodeB, "length", 3d );
  Relationship relAC = createRelationship( nodeA, nodeB, "length", 10d );
  </code></pre>
  
  <p>Thanks!</p>