From: Thomas Walker Lynch Date: Fri, 3 Jan 2025 10:25:48 +0000 (+0000) Subject: chkpt this mess X-Git-Url: https://git.reasoningtechnology.com/usr/lib/python2.7/encodings/tis_620.py?a=commitdiff_plain;h=f90d1c7aa3bfb45b1c41fa4513ca20dbb569743e;p=Ariadne chkpt this mess --- diff --git a/developer/deprecated/Ariadne_IdentityManager.java b/developer/deprecated/Ariadne_IdentityManager.java new file mode 100644 index 0000000..a956a9b --- /dev/null +++ b/developer/deprecated/Ariadne_IdentityManager.java @@ -0,0 +1,63 @@ +/* +General purpose identity manager. Gives names to things. + + +*/ +package com.ReasoningTechnology.Ariadne; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +// General-purpose Identity Manager +public class IdentityManager implements Ariadne_ResourceIdentity{ + + private final String namespace; + private final AtomicInteger counter; + private final ConcurrentHashMap registry; + + public IdentityManager( String namespace ){ + if( namespace == null || namespace.isEmpty() ){ + throw new IllegalArgumentException( "IdentityManager::namespace cannot be null or empty." ); + } + this.namespace = namespace; + this.counter = new AtomicInteger(0); + this.registry = new ConcurrentHashMap<>(); + } + + public synchronized String generate_name(){ + return namespace + "_" + counter.incrementAndGet(); + } + + public synchronized void register( ResourceIdentity resource ){ + if( resource == null ){ + throw new IllegalArgumentException( "IdentityManager::resource cannot be null." ); + } + + String name = resource.get_name(); + if( name == null ){ + name = generate_name(); + resource.set_name( name ); + } + resource.lock_name(); + + if( registry.containsKey( name ) ){ + throw new IllegalArgumentException( "IdentityManager::name already exists: " + name ); + } + + registry.put( name ,resource ); + } + + public synchronized ResourceIdentity get_resource( String name ){ + return registry.get( name ); + } + + public synchronized void unregister( String name ){ + registry.remove( name ); + } + + @Override + public String toString(){ + return "IdentityManager{namespace='" + namespace + "' ,registeredResources=" + registry.keySet() + "}"; + } + +} diff --git a/developer/deprecated/Ariadne_LockManager.java b/developer/deprecated/Ariadne_LockManager.java new file mode 100644 index 0000000..21bdb05 --- /dev/null +++ b/developer/deprecated/Ariadne_LockManager.java @@ -0,0 +1,12 @@ +/* + + +*/ + + +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_LockManager{ + Ariadne_LockManagerDelegate single_thread(Object resource); + Ariadne_LockManagerDelegate multiple_thread(Object resource); +} diff --git a/developer/deprecated/Ariadne_LockManagerDelegate.java b/developer/deprecated/Ariadne_LockManagerDelegate.java new file mode 100644 index 0000000..1b46908 --- /dev/null +++ b/developer/deprecated/Ariadne_LockManagerDelegate.java @@ -0,0 +1,6 @@ +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_LockManagerDelegate{ + void request(); + void relinquish(); +} diff --git a/developer/deprecated/Ariadne_SRM_with_locks.java b/developer/deprecated/Ariadne_SRM_with_locks.java new file mode 100644 index 0000000..14cf1fa --- /dev/null +++ b/developer/deprecated/Ariadne_SRM_with_locks.java @@ -0,0 +1,108 @@ +/* +Step Right Machine + +This is a mostly abstract base class. + +The SRM is for a single traversal through a bound resources. + +In Java it is possible to declare a variable of the SRM type long before it is used +for traversal. This complicates managing ownwership of the resource being traversed. + +The SRM model is that of 'mount' and 'dismount'. When the resource is mounted, +the SRM requests ownership of it. When it is dismounted, the SRM relinquishes +ownership. + + + +mount and unmount are used for handling shared memory scenarios. See +the Ariadne_Access class. For single threaded execution pass in an +Ariadne_Access_Single instance. + +*/ + +package com.ReasoningTechnology.Ariadne; + +public class Ariadne_SRM{ + + public enum Topology{ + NO_CELLS + ,SEGMENT + ,CIRCLE + ,INFINITE_RIGHT + ,INFINITE_LEFT + ,INFINITE + ,UNKNOWN + ,UNDEFINED + ; + } + + public Topology topology(){ + return Topology.UNDEFINED; + } + + public enum Status{ + TAPE_NOT_MOUNTED + ,LEFTMOST + ,INTERIM + ,RIGHTMOST + ; + } + + public Status status(){ + throw new UnsupportedOperationException("Ariadne_SRM::status not implemented."); + } + + public boolean can_step(){ + return + status() == Status.LEFTMOST + || status() == Status.INTERIM; + } + + public boolean can_read(){ + return status() != Status.TAPE_NOT_MOUNTED; + } + + public static Ariadne_SRM make(LockManagerDelegate delegate){ + if(delegate == null){ + throw new IllegalArgumentException("Ariadne_SRM::make delegate cannot be null."); + } + return new Ariadne_SRM<>(delegate); + } + + private Ariadne_SRM(LockManagerDelegate delegate){ + this.delegate = delegate; + } + + public void mount(){ + if(status() != Status.TAPE_NOT_MOUNTED){ + throw new IllegalStateException("Ariadne_SRM::mount already mounted."); + } + delegate.request(this); + } + public void mount_lenient() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Ensure the current tape is dismounted first + } + mount(); // Proceed to mount the new tape + } + + public void dismount(){ + if(status() == Status.TAPE_NOT_MOUNTED){ + throw new IllegalStateException("Ariadne_SRM::dismount not mounted."); + } + delegate.relinquish(this); + } + public void dismount_lenient() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Only dismount if a tape is currently mounted + } + } + + public T read(){ + throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); + } + + public void step(){ + throw new UnsupportedOperationException("Ariadne_SRM::step not implemented."); + } +} diff --git a/developer/deprecated/hold/Ariadne_DirectedGraph.java b/developer/deprecated/hold/Ariadne_DirectedGraph.java new file mode 100644 index 0000000..941d935 --- /dev/null +++ b/developer/deprecated/hold/Ariadne_DirectedGraph.java @@ -0,0 +1,26 @@ +package com.ReasoningTechnology.Ariadne; + +/* + To define a graph, extend this class and define `lookup`. + + For a wellformed graph, each start label will be a label for a node found in the graph. +*/ + + +import java.util.HashMap; +import java.util.Map; + +package com.ReasoningTechnology.Ariadne; + +public class Ariadne_Graph{ + + public static Ariadne_DirectedGraph make(Object...obj_list){ + return new Ariadne_DirectedGraph(); + } + + public Ariadne_StepRightMachine start(); + public Ariadne_StepRightMachine traverse(); + public Ariadne_Node lookup(String label); + + +} diff --git a/developer/deprecated/hold/Ariadne_NodeList.xjava b/developer/deprecated/hold/Ariadne_NodeList.xjava new file mode 100644 index 0000000..69e4284 --- /dev/null +++ b/developer/deprecated/hold/Ariadne_NodeList.xjava @@ -0,0 +1,10 @@ +// NodeList.java +package com.ReasoningTechnology.Ariadne; +import java.util.ArrayList; + +public class Ariadne_NodeList extends ArrayList { + // Constructor + public Ariadne_NodeList(){ + super(); + } +} diff --git "a/developer/document\360\237\226\211/graph_print.html" "b/developer/document\360\237\226\211/graph_print.html" index 039ebc8..2945154 100644 --- "a/developer/document\360\237\226\211/graph_print.html" +++ "b/developer/document\360\237\226\211/graph_print.html" @@ -309,7 +309,7 @@ This algorithm avoids forward referencing by ensuring that nodes are processed a
  • Yield a node from the list (one at a time).
  • If the list becomes empty, remove it from list_of__opened_incomplete_child_list.
  • -
  • Print the node.
  • +
  • queue the node as the read value.
  • If the node has its own child list, add it to list_of__unopened_node.
diff --git a/developer/example/CountingNumber.class b/developer/example/CountingNumber.class index cce86a0..2df2a30 100644 Binary files a/developer/example/CountingNumber.class and b/developer/example/CountingNumber.class differ diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java index 7cd8a37..c0f7871 100644 --- a/developer/example/CountingNumber.java +++ b/developer/example/CountingNumber.java @@ -7,26 +7,32 @@ public class CountingNumber extends Ariadne_SRM{ private static final Ariadne_Test test = Ariadne_Test.make("Ariadne_SRM::"); public static CountingNumber make(){ - return new CountingNumber(); + return new CountingNumber(null); + } + public static CountingNumber make(BigInteger maximum){ + return new CountingNumber(maximum); } private BigInteger i; + private BigInteger maximum; + Ariadne_SRM.Status status; - protected CountingNumber(){ - super(); - i = BigInteger.ZERO; + protected CountingNumber(BigInteger maximum){ + i = BigInteger.ONE; + this.maximum = maximum; + this.status = Status.LEFTMOST; test.print("CountingNumber read() value initialized to: " + i); } @Override public Topology topology(){ - return Topology.INFINITE_RIGHT; // leftmost, no rightmost + if(maximum == null) return Topology.INFINITE_RIGHT; + return Topology.SEGMENT; } @Override public Status status(){ - if( i.equals(BigInteger.ZERO) ) return Status.LEFTMOST; - else return Status.INTERIM; + return status; } @Override @@ -35,10 +41,19 @@ public class CountingNumber extends Ariadne_SRM{ } @Override - public boolean step(){ + public void step(){ + super.step(); i = i.add(BigInteger.ONE); - test.print(" after step right new read() value: " + i); - return true; + + if(topology() == Topology.SEGMENT){ + if(i.compareTo(maximum) == 0){ + status = Status.RIGHTMOST; + }else if(status() == Status.LEFTMOST){ + status = Status.INTERIM; + } + } + + test.print(" after step, new read() value: " + i); } } diff --git a/developer/example/Example_CountingNumber b/developer/example/Example_CountingNumber new file mode 100755 index 0000000..624ad06 --- /dev/null +++ b/developer/example/Example_CountingNumber @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_CountingNumber diff --git a/developer/example/Example_CountingNumber.class b/developer/example/Example_CountingNumber.class new file mode 100644 index 0000000..aee2ee4 Binary files /dev/null and b/developer/example/Example_CountingNumber.class differ diff --git a/developer/example/Example_CountingNumber.java b/developer/example/Example_CountingNumber.java new file mode 100644 index 0000000..a635ac0 --- /dev/null +++ b/developer/example/Example_CountingNumber.java @@ -0,0 +1,43 @@ +/* +Donald Knuth pointed out in the Art of Computer Programming, that there +is a mid-test loop missing from most languages. The mid-test loop works +well with inclusive bound loops, as is needed with the SRM. + +*/ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import java.math.BigInteger; + +public class Example_CountingNumber{ + + protected static void print_ten(CountingNumber n){ + System.out.println("Iterating through Counting Numbers:"); + if( !n.mounted() ) return; + if(n.topology() == Ariadne_SRM.Topology.SEGMENT){ + + do{ + System.out.println("Current Number: " + n.read()); + if( n.status() == Ariadne_SRM.Status.RIGHTMOST ) break; + n.step(); + }while(true); + + }else if(n.topology() == Ariadne_SRM.Topology.INFINITE_RIGHT){ + + int i = 1; + do{ + System.out.println("Current Number: " + n.read()); + if( i == 10 ) break; + n.step(); + i++; + }while(true); + + } else { + System.out.println("Unrecognized tape topology."); + } + } + + public static void main(String[] args){ + print_ten(CountingNumber.make(BigInteger.TEN)); + print_ten(CountingNumber.make()); + + } +} diff --git a/developer/example/Example_IdentityManager_0.java b/developer/example/Example_IdentityManager_0.java deleted file mode 100644 index 15bf9f6..0000000 --- a/developer/example/Example_IdentityManager_0.java +++ /dev/null @@ -1,50 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_IdentityManager; - - -// Example Resource Class -class ExampleResource{ - - private final String name; - - public ExampleResource( String name ){ - this.name = name; - } - - public String get_name(){ - return name; - } - - @Override - public String toString(){ - return "ExampleResource{name='" + name + "'}"; - } - -} - -class Example_IdentityManager_0 { - - public static void main( String[] args ){ - IdentityManager manager = new IdentityManager<>( "ResourceNamespace" ); - - // Create resources and register them - String name1 = manager.generate_name(); - ExampleResource resource1 = new ExampleResource( name1 ); - manager.register( name1 ,resource1 ); - - String name2 = manager.generate_name(); - ExampleResource resource2 = new ExampleResource( name2 ); - manager.register( name2 ,resource2 ); - - // Access resources - System.out.println( "Resource 1: " + manager.get_resource( name1 ) ); - System.out.println( "Resource 2: " + manager.get_resource( name2 ) ); - - // Print all registered resources - System.out.println( manager ); - - // Unregister a resource - manager.unregister( name1 ); - System.out.println( "After unregistration: " + manager ); - } - -} diff --git a/developer/example/Example_IndexTree_0 b/developer/example/Example_IndexTree_0 new file mode 100755 index 0000000..f6eac3c --- /dev/null +++ b/developer/example/Example_IndexTree_0 @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_IndexTree_0 diff --git a/developer/example/Example_IndexTree_0.class b/developer/example/Example_IndexTree_0.class new file mode 100644 index 0000000..1aa7f73 Binary files /dev/null and b/developer/example/Example_IndexTree_0.class differ diff --git a/developer/example/Example_IndexTree_0.java b/developer/example/Example_IndexTree_0.java index 306e475..296b499 100644 --- a/developer/example/Example_IndexTree_0.java +++ b/developer/example/Example_IndexTree_0.java @@ -1,36 +1,53 @@ -import java.math.BigInteger; -import java.util.List; -import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Graph; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Child_SRM; import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import java.math.BigInteger; -public class Example_IndexTree_0 { +public class Example_IndexTree_0{ - public static void main(String[] args){ - // Create the IndexTree graph - Ariadne_IndexTree_Graph graph = new Ariadne_IndexTree_Graph(); - Ariadne_SRM srm = graph.start(); - - System.out.println("Starting Depth-First Traversal:"); - // Depth-First Traversal: Visit the leftmost child at each level - for (int i = 0; i < 4; i++){ - System.out.println("Step " + i + ": " + srm.read()); - srm = srm.neighbor(); // Move to the leftmost child - } + public static void traverse_index_tree(){ + System.out.println("Starting Index Tree Traversal:"); - System.out.println("\nStarting Breadth-First Traversal:"); - // Breadth-First Traversal: Visit all siblings before descending - for (int i = 0; i < 4; i++){ - System.out.println("Step " + i + ": " + srm.read()); - srm.step_right(); // Move to the next sibling - } + Ariadne_IndexTree_Node root_node = Ariadne_IndexTree_Node.make(new BigInteger[0]); + System.out.println("Root Node: " + format_label(root_node.label())); + + Ariadne_IndexTree_Node current_node = root_node; + int depth_count = 0; + do{ + Ariadne_IndexTree_Child_SRM depth_srm = current_node.neighbor(); + BigInteger[] depth_label = depth_srm.read(); + System.out.println("Step " + (depth_count + 1) + " Down: " + format_label(depth_label)); + current_node = Ariadne_IndexTree_Node.make(depth_label); + + // precise loop termination + if(depth_count == 3) break; + depth_count++; + }while(true); - System.out.println("\nStarting Diagonal Walk:"); - // Diagonal Walk: Alternate between descending and stepping right - for (int i = 0; i < 4; i++){ - System.out.println("Step " + i + ": " + srm.read()); - srm = srm.neighbor(); // Move to the first child - srm.step_right(); // Step to the sibling + Ariadne_IndexTree_Child_SRM child_srm = current_node.neighbor(); + int child_count = 0; + do{ + BigInteger[] child_label = child_srm.read(); + System.out.println("Step " + (child_count + 1) + " Across: " + format_label(child_label)); + + // precise loop termination + if(child_count == 3) break; // Mid-loop test for inclusive bound + child_count++; + child_srm.step(); + }while(true); + } + + private static String format_label(BigInteger[] label){ + if(label.length == 0) return "[]"; + StringBuilder formatted = new StringBuilder("["); + for(int i = 0 ;i < label.length ;i++){ + formatted.append(label[i].toString()); + if(i < label.length - 1) formatted.append(" ,"); } + formatted.append("]"); + return formatted.toString(); + } + + public static void main(String[] args){ + traverse_index_tree(); } } diff --git a/developer/example/Example_IndexTree_Diagonal_SRM b/developer/example/Example_IndexTree_Diagonal_SRM new file mode 100755 index 0000000..5b45c16 --- /dev/null +++ b/developer/example/Example_IndexTree_Diagonal_SRM @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_IndexTree_Diagonal_SRM diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.class b/developer/example/Example_IndexTree_Diagonal_SRM.class new file mode 100644 index 0000000..7f9b08e Binary files /dev/null and b/developer/example/Example_IndexTree_Diagonal_SRM.class differ diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.java b/developer/example/Example_IndexTree_Diagonal_SRM.java new file mode 100644 index 0000000..746735a --- /dev/null +++ b/developer/example/Example_IndexTree_Diagonal_SRM.java @@ -0,0 +1,39 @@ +import java.math.BigInteger; +import java.util.Queue; + +public class Example_IndexTree_Diagonal_SRM { + + public static void main(String[] args){ + System.out.println("Starting IndexTree SRM Example"); + + // Instantiate the IndexTree Diagonal SRM + IndexTree_Diagonal_SRM srm = IndexTree_Diagonal_SRM.make(); + + int step_count = 0; + do{ + System.out.println("Step " + (step_count + 1) + ":"); + /* + Queue read_list = srm.read(); + if(!read_list.isEmpty()){ + for(BigInteger[] label : read_list){ + System.out.println(" Node Label: " + format_label(label)); + } + } + */ + if(step_count == 3) break; // Mid-loop test for inclusive bounds + step_count++; + srm.step(); + }while(true); + } + + private static String format_label(BigInteger[] label){ + if(label.length == 0) return "[]"; + StringBuilder formatted = new StringBuilder("["); + for(int i = 0; i < label.length; i++){ + formatted.append(label[i].toString()); + if(i < label.length - 1) formatted.append(" ,"); + } + formatted.append("]"); + return formatted.toString(); + } +} diff --git a/developer/example/Example_SRMI_Array b/developer/example/Example_SRMI_Array new file mode 100755 index 0000000..80c5dbd --- /dev/null +++ b/developer/example/Example_SRMI_Array @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_SRMI_Array diff --git a/developer/example/Example_SRMI_Array.class b/developer/example/Example_SRMI_Array.class new file mode 100644 index 0000000..4917a44 Binary files /dev/null and b/developer/example/Example_SRMI_Array.class differ diff --git a/developer/example/Example_SRMI_Array.java b/developer/example/Example_SRMI_Array.java index 93a96c4..b3e9b99 100644 --- a/developer/example/Example_SRMI_Array.java +++ b/developer/example/Example_SRMI_Array.java @@ -6,11 +6,13 @@ import java.util.List; public class Example_SRMI_Array { public static void main( String[] args ) { + /* + // Create a list - List labels = Arrays.asList( "A" ,"B" ,"C" ,"D" ); + List label_list = Arrays.asList( "A" ,"B" ,"C" ,"D" ); // Attach SRMI to the list - Ariadne_SRMI_Array srm = Ariadne_SRMI_Array.attach( labels ); + Ariadne_SRMI_Array srm = Ariadne_SRMI_Array.make( label_list ); // Use the SRMI System.out.println( "Topology: " + srm.topology() ); @@ -25,5 +27,7 @@ public class Example_SRMI_Array { // Final item System.out.println( "Reading: " + srm.read() ); System.out.println( "Status: " + srm.status() ); + + */ } } diff --git a/developer/example/Example_SRM_0.java b/developer/example/Example_SRM_0.java deleted file mode 100644 index bd8a9b3..0000000 --- a/developer/example/Example_SRM_0.java +++ /dev/null @@ -1,23 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; - -import java.math.BigInteger; - -public class Example_SRM_0{ - - public static void main(String[] args){ - CountingNumber counting_number = CountingNumber.make(); - - System.out.println("Initial Status: " + counting_number.status()); - System.out.println("Initial Read Value: " + counting_number.read()); - - for( int step_index = 0 ;step_index < 10 ;step_index++ ){ - counting_number.step(); - System.out.println( - "Step: " + step_index - +", Status: " + counting_number.status() - +", Read Value: " + counting_number.read() - ); - } - } -} - diff --git a/developer/example/Example_SRM_1.java b/developer/example/Example_SRM_1.java deleted file mode 100644 index 213b567..0000000 --- a/developer/example/Example_SRM_1.java +++ /dev/null @@ -1,55 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; - -import java.util.Arrays; -import java.util.List; - -public class Example_Ariadne_SRM_1{ - - public static class SimpleLockManagerDelegate implements Ariadne_LockManagerDelegate{ - - @Override - public void request(Object srm){ - System.out.println("LockManagerDelegate: Lock acquired for " + srm); - } - - @Override - public void relinquish(Object srm){ - System.out.println("LockManagerDelegate: Lock released for " + srm); - } - } - - public static void main(String[] args){ - // Create a LockManagerDelegate - Ariadne_LockManagerDelegate delegate = new SimpleLockManagerDelegate(); - - // Create an SRM instance with the delegate - Ariadne_SRM srm = Ariadne_SRM.make(delegate); - - // Define a list to iterate over - List list = Arrays.asList(10 ,20 ,30 ,40 ,50); - - // Mount the list on the SRM - try{ - srm.mount(); - System.out.println("Mounted SRM. Status: " + srm.status()); - - // Iterate through the list - for(Integer value : list){ - System.out.println("Read value: " + value); - } - - // Dismount the SRM - srm.dismount(); - System.out.println("Dismounted SRM. Status: " + srm.status()); - }catch(IllegalStateException e){ - System.err.println("Error: " + e.getMessage()); - } - - // Demonstrate lenient methods - System.out.println("\nUsing lenient methods:"); - srm.lenient_mount(); - System.out.println("Lenient mount complete. Status: " + srm.status()); - srm.lenient_dismount(); - System.out.println("Lenient dismount complete. Status: " + srm.status()); - } -} diff --git a/developer/example/Example_SRM_List b/developer/example/Example_SRM_List new file mode 100755 index 0000000..e0d48dd --- /dev/null +++ b/developer/example/Example_SRM_List @@ -0,0 +1,2 @@ +#!/bin/bash +java Example_SRM_List diff --git a/developer/example/Example_SRM_List.class b/developer/example/Example_SRM_List.class new file mode 100644 index 0000000..acee04a Binary files /dev/null and b/developer/example/Example_SRM_List.class differ diff --git a/developer/example/Example_SRM_List.java b/developer/example/Example_SRM_List.java index 772afde..dd90028 100644 --- a/developer/example/Example_SRM_List.java +++ b/developer/example/Example_SRM_List.java @@ -1,35 +1,35 @@ import com.ReasoningTechnology.Ariadne.Ariadne_SRM; import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; -import java.util.List; +import java.util.LinkedList; public class Example_SRM_List { - public static void main( String[] args ) { + public static void main(String[] args) { // Create a linked list - List labels = new List<>(); - labels.add( "A" ); - labels.add( "B" ); - labels.add( "C" ); + LinkedList labels = new LinkedList<>(); + labels.add("A"); + labels.add("B"); + labels.add("C"); - // Attach SRMI to the linked list - Ariadne_SRMI_List srm = Ariadne_SRMI_List.attach( labels ); + // Attach SRM to the linked list + Ariadne_SRM_List srm = Ariadne_SRM_List.attach(labels); - // Use the SRMI - System.out.println( "Topology: " + srm.topology() ); - System.out.println( "Status: " + srm.status() ); + // Use the SRM + System.out.println("Topology: " + srm.topology()); + System.out.println("Initial Status: " + srm.status()); // Traverse the list - while( srm.status() != Ariadne_SRM.Status.RIGHTMOST ) { - System.out.println( "Reading: " + srm.read() ); + while (srm.status() != Ariadne_SRM.Status.RIGHTMOST) { + System.out.println("Reading: " + srm.read()); srm.step(); } // Final item - System.out.println( "Reading: " + srm.read() ); - System.out.println( "Status: " + srm.status() ); + System.out.println("Reading: " + srm.read()); + System.out.println("Final Status: " + srm.status()); // Reset the SRM and traverse again srm.reset(); - System.out.println( "After reset: " + srm.read() ); + System.out.println("After reset: " + srm.read()); } } diff --git a/developer/example/IndexTree_Diagonal_SRM.java b/developer/example/IndexTree_Diagonal_SRM.java new file mode 100644 index 0000000..42f44db --- /dev/null +++ b/developer/example/IndexTree_Diagonal_SRM.java @@ -0,0 +1,80 @@ +import java.math.BigInteger; +import com.ReasoningTechnology.Ariadne.Ariadne_Test; +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; + +public class IndexTree_Diagonal_SRM extends Ariadne_SRM { + + private final Ariadne_SRM_List list_of__unopened_node; + private final Ariadne_SRM_List> list_of__opened_incomplete_child_list; + private final Ariadne_SRM_List read_list; + private final Ariadne_Test tester; + + public static IndexTree_Diagonal_SRM make(){ + return new IndexTree_Diagonal_SRM(); + } + + protected IndexTree_Diagonal_SRM(){ + this.list_of__unopened_node = new Ariadne_SRM_List<>(); + this.list_of__opened_incomplete_child_list = new Ariadne_SRM_List<>(); + this.read_list = new Ariadne_SRM_List<>(); + this.tester = Ariadne_Test.make("IndexTree_Diagonal_SRM: "); + enqueue_root(); + } + + @Override + public void step(){ + super.step(); + + read_list.clear(); // Clear the current read list for the new diagonal + + // Process unopened nodes + while(!list_of__unopened_node.is_empty()){ + Ariadne_IndexTree_Node node = list_of__unopened_node.read(); + list_of__unopened_node.step(); // Remove node from unopened list + Ariadne_SRM_List child_list = node.open(); + if(child_list != null){ + list_of__opened_incomplete_child_list.add(child_list); + } + } + + // Process incomplete child lists + while(!list_of__opened_incomplete_child_list.is_empty()){ + Ariadne_SRM_List child_list = list_of__opened_incomplete_child_list.read(); + if(!child_list.is_empty()){ + Ariadne_IndexTree_Node node = child_list.read(); + child_list.step(); // Step to the next node in the child list + BigInteger[] label = node.label(); + read_list.add(label); // Queue the label on the read list + tester.print("Queued label: " + format_label(label)); + if(node.has_children()){ + list_of__unopened_node.add(node); // Add node to unopened list if it has children + } + if(child_list.is_empty()){ + list_of__opened_incomplete_child_list.step(); // Remove empty child lists + } + } + } + } + + private void enqueue_root(){ + Ariadne_IndexTree_Node root = Ariadne_IndexTree_Node.make(new BigInteger[0]); + read_list.add(root.label()); + tester.print("Queued root label: " + format_label(root.label())); + if(root.has_children()){ + list_of__unopened_node.add(root); + } + } + + private String format_label(BigInteger[] label){ + if(label.length == 0) return "[]"; + StringBuilder formatted = new StringBuilder("["); + for(int i = 0; i < label.length; i++){ + formatted.append(label[i].toString()); + if(i < label.length - 1) formatted.append(" ,"); + } + formatted.append("]"); + return formatted.toString(); + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_Graph.java" index 5c95392..51cbfd2 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Graph.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Graph.java" @@ -2,18 +2,20 @@ User defines a graph by implementing this interface. For the build tool, the defined graph is dynamically loaded. + Generally labels are returned and passed around. Only `lookup` returns a Node. + In a wellformed graph, the labels returned by `start()` will be in the graph. This can be checked by calling `lookup`. */ package com.ReasoningTechnology.Ariadne; -public interface Ariadne_Graph { +public interface Ariadne_Graph { - // One or more nodes for starting graph traversals - Ariadne_SRM start(); + // returns list of TLabel + Ariadne_SRM start(); - // Method to look up a node by label - Ariadne_Node lookup(T label); + // lookup a Node by label + Ariadne_Node lookup(TLabel label); } diff --git "a/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" "b/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" deleted file mode 100644 index a956a9b..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" +++ /dev/null @@ -1,63 +0,0 @@ -/* -General purpose identity manager. Gives names to things. - - -*/ -package com.ReasoningTechnology.Ariadne; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -// General-purpose Identity Manager -public class IdentityManager implements Ariadne_ResourceIdentity{ - - private final String namespace; - private final AtomicInteger counter; - private final ConcurrentHashMap registry; - - public IdentityManager( String namespace ){ - if( namespace == null || namespace.isEmpty() ){ - throw new IllegalArgumentException( "IdentityManager::namespace cannot be null or empty." ); - } - this.namespace = namespace; - this.counter = new AtomicInteger(0); - this.registry = new ConcurrentHashMap<>(); - } - - public synchronized String generate_name(){ - return namespace + "_" + counter.incrementAndGet(); - } - - public synchronized void register( ResourceIdentity resource ){ - if( resource == null ){ - throw new IllegalArgumentException( "IdentityManager::resource cannot be null." ); - } - - String name = resource.get_name(); - if( name == null ){ - name = generate_name(); - resource.set_name( name ); - } - resource.lock_name(); - - if( registry.containsKey( name ) ){ - throw new IllegalArgumentException( "IdentityManager::name already exists: " + name ); - } - - registry.put( name ,resource ); - } - - public synchronized ResourceIdentity get_resource( String name ){ - return registry.get( name ); - } - - public synchronized void unregister( String name ){ - registry.remove( name ); - } - - @Override - public String toString(){ - return "IdentityManager{namespace='" + namespace + "' ,registeredResources=" + registry.keySet() + "}"; - } - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" new file mode 100644 index 0000000..ee9cec5 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" @@ -0,0 +1,38 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; + +public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM { + + private BigInteger[] label; + + public static Ariadne_IndexTree_Child_SRM make(BigInteger[] initial_label){ + return new Ariadne_IndexTree_Child_SRM(initial_label); + } + + protected Ariadne_IndexTree_Child_SRM(BigInteger[] initial_label){ + super(); + if (initial_label == null || initial_label.length == 0) { + throw new IllegalArgumentException("Initial label must not be null or empty."); + } + this.label = initial_label; + } + + @Override + public Topology topology(){ + return Topology.INFINITE_RIGHT; + } + + @Override + public BigInteger[] read(){ + // Return a reference to the current label + return label; + } + + @Override + public void step(){ + int max_index = label.length - 1; + label[max_index] = label[max_index].add(BigInteger.ONE); + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" index 9dbcf60..5924bb4 100644 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" @@ -5,8 +5,8 @@ import java.math.BigInteger; public class Ariadne_IndexTree_Graph implements Ariadne_Graph{ @Override - public Ariadne_IndexTree_SRM start(){ - return Ariadne_IndexTree_SRM.make(new BigInteger[0]); + public Ariadne_IndexTree_Child_SRM start(){ + return Ariadne_IndexTree_Child_SRM.make(new BigInteger[0]); } @Override @@ -15,3 +15,4 @@ public class Ariadne_IndexTree_Graph implements Ariadne_Graph{ } } + diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" index 405ca2a..44a4eb5 100644 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" @@ -14,8 +14,15 @@ public class Ariadne_IndexTree_Node extends Ariadne_Node { } @Override - public Ariadne_IndexTree_SRM neighbor(){ - return new Ariadne_IndexTree_SRM(label()); + public Ariadne_IndexTree_Child_SRM neighbor(){ + // Copy the current label + BigInteger[] parentLabel = this.label(); + BigInteger[] childLabel = new BigInteger[parentLabel.length + 1]; + System.arraycopy(parentLabel, 0, childLabel, 0, parentLabel.length); + + childLabel[parentLabel.length] = BigInteger.ZERO; + + return Ariadne_IndexTree_Child_SRM.make(childLabel); } @Override diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" deleted file mode 100644 index b70c8a5..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" +++ /dev/null @@ -1,40 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -import java.math.BigInteger; - -public class Ariadne_IndexTree_SRM extends Ariadne_SRM { - - private final BigInteger[] current_label; - - public static Ariadne_IndexTree_SRM make(BigInteger[] initial_label){ - return new Ariadne_IndexTree_SRM(initial_label); - } - - protected Ariadne_IndexTree_SRM(BigInteger[] initial_label){ - super(); - if (initial_label == null || initial_label.length == 0) { - throw new IllegalArgumentException("Initial label must not be null or empty."); - } - this.current_label = initial_label; - } - - @Override - public Topology topology(){ - return Topology.INFINITE_RIGHT; - } - - @Override - public BigInteger[] read(){ - // Return a reference to the current label - return current_label; - } - - @Override - public boolean step(){ - // Increment the last element of the label (child counter) - int lastIndex = current_label.length - 1; - current_label[lastIndex] = current_label[lastIndex].add(BigInteger.ONE); - return true; - } - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_LockManager.java" "b/developer/javac\360\237\226\211/Ariadne_LockManager.java" deleted file mode 100644 index 21bdb05..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_LockManager.java" +++ /dev/null @@ -1,12 +0,0 @@ -/* - - -*/ - - -package com.ReasoningTechnology.Ariadne; - -public interface Ariadne_LockManager{ - Ariadne_LockManagerDelegate single_thread(Object resource); - Ariadne_LockManagerDelegate multiple_thread(Object resource); -} diff --git "a/developer/javac\360\237\226\211/Ariadne_LockManagerDelegate.java" "b/developer/javac\360\237\226\211/Ariadne_LockManagerDelegate.java" deleted file mode 100644 index 1b46908..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_LockManagerDelegate.java" +++ /dev/null @@ -1,6 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -public interface Ariadne_LockManagerDelegate{ - void request(); - void relinquish(); -} diff --git "a/developer/javac\360\237\226\211/Ariadne_Node.java" "b/developer/javac\360\237\226\211/Ariadne_Node.java" index e23e1a4..2aa34d1 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Node.java" @@ -31,44 +31,44 @@ package com.ReasoningTechnology.Ariadne; import java.util.HashMap; import java.util.HashSet; -public class Ariadne_Node extends HashMap { +public class Ariadne_Node extends HashMap { // Owned by the class - public static Ariadne_Node make(T label) { - return new Ariadne_Node<>(label) ; + public static Ariadne_Node make(TLabel label) { + return new Ariadne_Node<>(label); } // Data owned by the instance - private final T label ; - private final HashSet markSet ; - private static final String NEIGHBOR_PROPERTY_NAME = "neighbor_property" ; + private final TLabel label; + private final HashSet markSet; + private static final String NEIGHBOR_PROPERTY_NAME = "neighbor_property"; // Constructors - public Ariadne_Node(T label) { - super() ; - this.label = label ; - this.markSet = new HashSet<>() ; + public Ariadne_Node(TLabel label) { + super(); + this.label = label; + this.markSet = new HashSet<>(); } // Instance interface - public T label() { - return this.label ; + public TLabel label() { + return this.label; } - public Ariadne_SRM neighbor() { - return Ariadne_SRM.make() ; + public Ariadne_SRM neighbor() { + return Ariadne_SRM.make(); } public void mark(Ariadne_Token token) { - markSet.add(token) ; + markSet.add(token); } public boolean hasMark(Ariadne_Token token) { - return markSet.contains(token) ; + return markSet.contains(token); } public void removeMark(Ariadne_Token token) { - markSet.remove(token) ; + markSet.remove(token); } // Object interface @@ -77,6 +77,6 @@ public class Ariadne_Node extends HashMap { return "Ariadne_Node{" + "label=" + label + " ,markSet=" + markSet - + "}" ; + + "}"; } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" index 422718f..2c34a8e 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM.java" @@ -1,41 +1,34 @@ /* -Step Right Machine + Step Right Machine -This is a mostly abstract base class. - -The SRM is for a single traversal through a bound resources. - -In Java it is possible to declare a variable of the SRM type long before it is used -for traversal. This complicates managing ownwership of the resource being traversed. - -The SRM model is that of 'mount' and 'dismount'. When the resource is mounted, -the SRM requests ownership of it. When it is dismounted, the SRM relinquishes -ownership. - - - -mount and unmount are used for handling shared memory scenarios. See -the Ariadne_Access class. For single threaded execution pass in an -Ariadne_Access_Single instance. + This is a mostly abstract base class. */ package com.ReasoningTechnology.Ariadne; -public class Ariadne_SRM{ +public class Ariadne_SRM { + + public static Ariadne_SRM make(){ + return new Ariadne_SRM<>(); + } + protected Ariadne_SRM(){ + } public enum Topology{ NO_CELLS ,SEGMENT ,CIRCLE ,INFINITE_RIGHT - ,INFINITE_LEFT - ,INFINITE ,UNKNOWN ,UNDEFINED ; } + public Topology topology(){ + return Topology.UNDEFINED; + } + // categorizes the head location public enum Status{ TAPE_NOT_MOUNTED ,LEFTMOST @@ -43,69 +36,25 @@ public class Ariadne_SRM{ ,RIGHTMOST ; } - - private final LockManagerDelegate delegate; - - public static Ariadne_SRM make(LockManagerDelegate delegate){ - if(delegate == null){ - throw new IllegalArgumentException("Ariadne_SRM::make delegate cannot be null."); - } - return new Ariadne_SRM<>(delegate); - } - - private Ariadne_SRM(LockManagerDelegate delegate){ - this.delegate = delegate; - } - - public synchronized void mount(){ - if(status() != Status.TAPE_NOT_MOUNTED){ - throw new IllegalStateException("Ariadne_SRM::mount already mounted."); - } - delegate.request(this); - } - public void mount_lenient() { - if(status() != Status.TAPE_NOT_MOUNTED) { - dismount(); // Ensure the current tape is dismounted first - } - mount(); // Proceed to mount the new tape - } - - - public synchronized void dismount(){ - if(status() == Status.TAPE_NOT_MOUNTED){ - throw new IllegalStateException("Ariadne_SRM::dismount not mounted."); - } - delegate.relinquish(this); - } - public void dismount_lenient() { - if(status() != Status.TAPE_NOT_MOUNTED) { - dismount(); // Only dismount if a tape is currently mounted - } - } - - public synchronized Topology topology(){ - return Topology.UNDEFINED; - } - - public synchronized Status status(){ + public Status status(){ throw new UnsupportedOperationException("Ariadne_SRM::status not implemented."); } - - public synchronized boolean can_step(){ + public boolean can_step(){ return status() == Status.LEFTMOST || status() == Status.INTERIM; } - - public synchronized boolean can_read(){ + public boolean mounted(){ return status() != Status.TAPE_NOT_MOUNTED; } - public synchronized T read(){ + public TElement read(){ throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); } - public synchronized void step(){ - throw new UnsupportedOperationException("Ariadne_SRM::step not implemented."); + public void step(){ + if( !can_step() ) + throw new UnsupportedOperationException("Ariadne_SRM::step can not step."); } + } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" index 3ec1b76..cdb49a1 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" @@ -19,9 +19,9 @@ public class Ariadne_SRMI extends Ariadne_SRM{ } @Override - public boolean step(){ + public void step(){ throw new UnsupportedOperationException("Ariadne_SRMI::can't step unmounted tape."); - // index.add(BigInteger.ONE); +// index.add(BigInteger.ONE); } BigInteger index(){return index;} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" index 2dcefba..94fcbb7 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" @@ -17,38 +17,6 @@ public class Ariadne_SRMI_Array extends Ariadne_SRMI{ super(); } - public void mount(List list ,Semaphore semaphore){ - if(this.list != null){ - throw new IllegalStateException("Ariadne_SRMI_Array::mount tape already mounted."); - } - if(list == null){ - throw new IllegalArgumentException("Ariadne_SRMI_Array::mount list cannot be null."); - } - this.list = list; - this.lock = semaphore; - if(lock != null){ - try{ - lock.acquire(); - } catch(InterruptedException e){ - Thread.currentThread().interrupt(); - throw new IllegalStateException("Ariadne_SRMI_Array::mount interrupted while acquiring lock."); - } - } - set_status(list.isEmpty() ? Status.TAPE_NOT_MOUNTED : Status.LEFTMOST); - } - - public void unmount(){ - if(this.list == null){ - throw new IllegalStateException("Ariadne_SRMI_Array::unmount no tape mounted."); - } - this.list = null; - set_status(Status.TAPE_NOT_MOUNTED); - if(lock != null){ - lock.release(); - lock = null; - } - } - @Override public Topology topology(){ if(list == null || list.isEmpty()){ @@ -64,7 +32,7 @@ public class Ariadne_SRMI_Array extends Ariadne_SRMI{ @Override public T read(){ - if(!can_read()){ + if(!mounted()){ throw new UnsupportedOperationException("Ariadne_SRMI_Array::read tape not mounted or out of bounds."); } return list.get(index().intValue()); @@ -77,7 +45,7 @@ public class Ariadne_SRMI_Array extends Ariadne_SRMI{ } if(index().compareTo(rightmost_index()) < 0){ index = index.add(BigInteger.ONE); - set_status(index().equals(rightmost_index()) ? Status.RIGHTMOST : Status.INTERIM); +// set_status(index().equals(rightmost_index()) ? Status.RIGHTMOST : Status.INTERIM); } else{ throw new UnsupportedOperationException("Ariadne_SRMI_Array::step, no more cells."); } diff --git "a/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" "b/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" deleted file mode 100644 index 941d935..0000000 --- "a/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" +++ /dev/null @@ -1,26 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -/* - To define a graph, extend this class and define `lookup`. - - For a wellformed graph, each start label will be a label for a node found in the graph. -*/ - - -import java.util.HashMap; -import java.util.Map; - -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_Graph{ - - public static Ariadne_DirectedGraph make(Object...obj_list){ - return new Ariadne_DirectedGraph(); - } - - public Ariadne_StepRightMachine start(); - public Ariadne_StepRightMachine traverse(); - public Ariadne_Node lookup(String label); - - -} diff --git "a/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" "b/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" deleted file mode 100644 index 69e4284..0000000 --- "a/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" +++ /dev/null @@ -1,10 +0,0 @@ -// NodeList.java -package com.ReasoningTechnology.Ariadne; -import java.util.ArrayList; - -public class Ariadne_NodeList extends ArrayList { - // Constructor - public Ariadne_NodeList(){ - super(); - } -} diff --git "a/developer/tool\360\237\226\211/make_example" "b/developer/tool\360\237\226\211/make_example" index b766bd5..3cd18be 100755 --- "a/developer/tool\360\237\226\211/make_example" +++ "b/developer/tool\360\237\226\211/make_example" @@ -9,30 +9,37 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") exit 1 fi - cd "$REPO_HOME"/developer - + cd "$REPO_HOME"/developer/example echo "Compiling example .java files..." set -x - cd example - javac -verbose -g -sourcepath . *.java + javac -g -sourcepath . *.java set +x + if [ $? -ne 0 ]; then echo "Compilation failed." exit 1 fi echo "Creating bash wrappers..." - # wrapper is a space separated list - wrapper=Example_*.class - for file in $wrapper;do - cat > $file << EOL + +set -x + +wrapper=(Example_*.class) + +for file in "${wrapper[@]}"; do + wrapper_name=$(basename "$file" .class) + cat > "$wrapper_name" << EOL #!/bin/bash -java $file +java $wrapper_name EOL - chmod +x $file - done + + # Make the wrapper executable + chmod +x "$wrapper_name" +done + +set +x echo "$(script_fp) done."