comp.lang.ada
 help / color / mirror / Atom feed
* Simple Components: adding an existing object to a graph
@ 2020-01-26 10:23 Mart van de Wege
  2020-01-26 13:10 ` Dmitry A. Kazakov
  2020-01-26 14:48 ` Jeffrey R. Carter
  0 siblings, 2 replies; 6+ messages in thread
From: Mart van de Wege @ 2020-01-26 10:23 UTC (permalink / raw)


This one's for Dimitry, probably: I want to create a genealogy of
persons using his generic directed weighted graph package.

I've seen how I can do that like this (example code, assuming an
instantiated Graph):

type Person is record
     Name: Unbounded_String,
     Age: Natural
end record;

and then adding it to the graph with:

Ancestor : Node := new Person;

However, assume I already have plenty of code to create and manipulate
Person objects, how do I assign an *existing* object of type Person to a
graph? Trying to do it the obvious way by assigning an access to Person
to a Node object gets me an error message that Node is not a general
access type.

Regards,

Mart van de Wege
-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Simple Components: adding an existing object to a graph
  2020-01-26 10:23 Simple Components: adding an existing object to a graph Mart van de Wege
@ 2020-01-26 13:10 ` Dmitry A. Kazakov
  2020-01-26 13:24   ` Mart van de Wege
  2020-01-26 14:48 ` Jeffrey R. Carter
  1 sibling, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2020-01-26 13:10 UTC (permalink / raw)


On 2020-01-26 11:23, Mart van de Wege wrote:
> This one's for Dimitry, probably: I want to create a genealogy of
> persons using his generic directed weighted graph package.
> 
> I've seen how I can do that like this (example code, assuming an
> instantiated Graph):
> 
> type Person is record
>       Name: Unbounded_String,
>       Age: Natural
> end record;
> 
> and then adding it to the graph with:
> 
> Ancestor : Node := new Person;
> 
> However, assume I already have plenty of code to create and manipulate
> Person objects, how do I assign an *existing* object of type Person to a
> graph? Trying to do it the obvious way by assigning an access to Person
> to a Node object gets me an error message that Node is not a general
> access type.

The design of the graph is based on keeping edges/links in the memory 
pool in front of the node itself. That prevents copying of nodes. Thus 
all instances of Person must be allocated in that pool, which is why the 
access type is pool-specific.

If persons need to be kept outside the pool, which I would not 
recommend, you could use a reference to person inside the node.

BTW, this is how Unbounded_String works. Name in Person actually is a 
wrapped access type to the string body allocated elsewhere. A compound 
design would rather be:

    type Person (Name_Length : Natural) is record -- Everything is here
       Age  : Natural;
       Name : String (1..Name_Length);
    end record;

P.S. For reference-counted object see Object.Handle, but don't see an 
immediate need of that. You should simply change function creating 
Person to return Node. The rest would remain.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Simple Components: adding an existing object to a graph
  2020-01-26 13:10 ` Dmitry A. Kazakov
@ 2020-01-26 13:24   ` Mart van de Wege
  0 siblings, 0 replies; 6+ messages in thread
From: Mart van de Wege @ 2020-01-26 13:24 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

>
> P.S. For reference-counted object see Object.Handle, but don't see an
> immediate need of that. You should simply change function creating
> Person to return Node. The rest would remain.

Ok, I was afraid of that. Off to go search&replace and see what
happens.

Thanks!

Mart

-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Simple Components: adding an existing object to a graph
  2020-01-26 10:23 Simple Components: adding an existing object to a graph Mart van de Wege
  2020-01-26 13:10 ` Dmitry A. Kazakov
@ 2020-01-26 14:48 ` Jeffrey R. Carter
  2020-01-26 15:39   ` Mart van de Wege
  2020-01-26 15:49   ` Mart van de Wege
  1 sibling, 2 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2020-01-26 14:48 UTC (permalink / raw)


On 1/26/20 11:23 AM, Mart van de Wege wrote:
> This one's for Dimitry, probably: I want to create a genealogy of
> persons using his generic directed weighted graph package.

Since a genealogy is a tree, wouldn't it make more sense to use 
Ada.Containers.Multiway_Trees?

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Simple Components: adding an existing object to a graph
  2020-01-26 14:48 ` Jeffrey R. Carter
@ 2020-01-26 15:39   ` Mart van de Wege
  2020-01-26 15:49   ` Mart van de Wege
  1 sibling, 0 replies; 6+ messages in thread
From: Mart van de Wege @ 2020-01-26 15:39 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> On 1/26/20 11:23 AM, Mart van de Wege wrote:
>> This one's for Dimitry, probably: I want to create a genealogy of
>> persons using his generic directed weighted graph package.
>
> Since a genealogy is a tree, wouldn't it make more sense to use
> Ada.Containers.Multiway_Trees?

I looked at that first, but how would you model the fact that a child
has 2 parents in a tree? As far as I can see Multiway_Trees is still
stuck in the model that every child node can have only one parent.

My idea was to link nodes, which can have multiple connections, using
the family relationship as a weight (using an enumeration type for the
relationships).

Regards,

Mart

-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Simple Components: adding an existing object to a graph
  2020-01-26 14:48 ` Jeffrey R. Carter
  2020-01-26 15:39   ` Mart van de Wege
@ 2020-01-26 15:49   ` Mart van de Wege
  1 sibling, 0 replies; 6+ messages in thread
From: Mart van de Wege @ 2020-01-26 15:49 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> On 1/26/20 11:23 AM, Mart van de Wege wrote:
>> This one's for Dimitry, probably: I want to create a genealogy of
>> persons using his generic directed weighted graph package.
>
> Since a genealogy is a tree, wouldn't it make more sense to use
> Ada.Containers.Multiway_Trees?

Side note: A genealogy is only a tree if you only consider matrilineal
or patrilineal descent. A full genealogy is mathematically a Directed
Acyclic Graph.

Mart

-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-26 15:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26 10:23 Simple Components: adding an existing object to a graph Mart van de Wege
2020-01-26 13:10 ` Dmitry A. Kazakov
2020-01-26 13:24   ` Mart van de Wege
2020-01-26 14:48 ` Jeffrey R. Carter
2020-01-26 15:39   ` Mart van de Wege
2020-01-26 15:49   ` Mart van de Wege

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox