New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain Class Hierarchy is not retained in Graph #40

Closed
nsengupta opened this Issue Jun 26, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@nsengupta

nsengupta commented Jun 26, 2015

Domain Type hierarchies are not honoured in scala-graph

I just created a hierarchy of types:

abstract class RootOfAllNode {
  def identifiedAs: String
}

class SubClassNodeA (id: Int) extends RootOfAllNode {
  def identifiedAs = "SubCLassNodeA (" + id  + ")"
}


class SubClassNodeB (price: Float) extends RootOfAllNode {
  def identifiedAs = "SubClassNodeB with price (" + price + ")"
}


// DateTime is actually org.joda.time.DateTime
class SubClassNodeC (createdOn: DateTime) extends RootOfAllNode {
  def identifiedAs = "SubClassNodeC (" + createdOn + ")"
}

Now, I intend to create a (Directed) Graph whose inhabitants are objects of the aforementioned types, thus:

import scalax.collection.GraphPredef._
import scalax.collection.GraphEdge._
import scalax.collection.GraphEdge.DiEdge
import scalax.collection.edge.LDiEdge     // labeled directed edge
import scalax.collection.edge.Implicits._ // shortcuts


import scalax.collection.edge.LBase._
object StringLabel extends LEdgeImplicits[String]


import StringLabel._


class Population {


  val a = new SubClassNodeA(9)
  val anotherA = new SubClassNodeA(10)
  val b = new SubClassNodeB(12.67f)
  val c = new SubClassNodeC(new DateTime(System.currentTimeMillis()))


  val family = Graph (
    (a ~+> b)("Loves"),                    // Works
    (b ~+> c)("Hates"),                    // Works
    (b ~+> a)("Ignores"),                  // Works
    (a ~+> anotherA)("notIntroducedYet")   // Doesn't work


  )
}

What the compiler comes back with is a mouthful! :-)

Error:(34, 8) type mismatch;
 found   : scalax.collection.edge.LDiEdge[org.nirmalya.graphExplore.SubClassNodeA] with scalax.collection.GraphEdge.EdgeCopy[scalax.collection.edge.LDiEdge]{type L1 = String}
 required: scalax.collection.GraphPredef.Param[org.nirmalya.graphExplore.RootOfAllNode,scalax.collection.edge.LDiEdge]
Note: org.nirmalya.graphExplore.SubClassNodeA <: org.nirmalya.graphExplore.RootOfAllNode (and scalax.collection.edge.LDiEdge[org.nirmalya.graphExplore.SubClassNodeA] with scalax.collection.GraphEdge.EdgeCopy[scalax.collection.edge.LDiEdge]{type L1 = String} <: scalax.collection.GraphPredef.Param[org.nirmalya.graphExplore.SubClassNodeA,scalax.collection.edge.LDiEdge]), but trait Param is invariant in type N.
You may wish to define N as +N instead. (SLS 4.5)
    (a ~+> anotherA)("notIntroducedYet")

If I create a Graph of objects of the Domain that application works in, it is quite likely that a Domain Class Hierarchy will exist. More so, because these objects will be created outside the Graph and then be held inside the Graph for easy access based on the relationships that exist between them. Therefore, somewhere, it will be expected that while it is being created, the Graph infers the Relationships between the Objects correctly.

Referring to the example I had provided, I am relating a SubClassNodeA to a SubClassNodeA, in the same way as a SubClassNodeA to a SubClassNodeB, because both of them IsA RootOfAllNode . In the Application Domain, this hierarchy is established. In the Graph, this is not honoured.

@0x203

This comment has been minimized.

Show comment
Hide comment
@0x203

0x203 Mar 10, 2016

Exactly the same problem I ran into. I would be glad to see this implemented, too!

Thanks for the great library, by the way!

0x203 commented Mar 10, 2016

Exactly the same problem I ran into. I would be glad to see this implemented, too!

Thanks for the great library, by the way!

@0x203

This comment has been minimized.

Show comment
Hide comment
@0x203

0x203 Mar 14, 2016

Cool, thanks, @peter-empen!

Can you tell me roughly when the next release will be (including this)?

0x203 commented Mar 14, 2016

Cool, thanks, @peter-empen!

Can you tell me roughly when the next release will be (including this)?

@peter-empen

This comment has been minimized.

Show comment
Hide comment
@peter-empen

peter-empen Mar 14, 2016

Contributor

You're welcome! I could pass a SNAPSHOT JAR to you for testing if that suffices.

Contributor

peter-empen commented Mar 14, 2016

You're welcome! I could pass a SNAPSHOT JAR to you for testing if that suffices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment