--- /dev/null
+/*
+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<T> implements Ariadne_ResourceIdentity<T>{
+
+ private final String namespace;
+ private final AtomicInteger counter;
+ private final ConcurrentHashMap<String ,ResourceIdentity> 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() + "}";
+ }
+
+}
--- /dev/null
+/*
+
+
+*/
+
+
+package com.ReasoningTechnology.Ariadne;
+
+public interface Ariadne_LockManager{
+ Ariadne_LockManagerDelegate<T> single_thread(Object resource);
+ Ariadne_LockManagerDelegate<T> multiple_thread(Object resource);
+}
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+public interface Ariadne_LockManagerDelegate{
+ void request();
+ void relinquish();
+}
--- /dev/null
+/*
+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<T>{
+
+ 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 <T> Ariadne_SRM<T> make(LockManagerDelegate<T> delegate){
+ if(delegate == null){
+ throw new IllegalArgumentException("Ariadne_SRM::make delegate cannot be null.");
+ }
+ return new Ariadne_SRM<>(delegate);
+ }
+
+ private Ariadne_SRM(LockManagerDelegate<T> 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.");
+ }
+}
--- /dev/null
+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<Ariadne_Node> start();
+ public Ariadne_StepRightMachine<Ariadne_Node> traverse();
+ public Ariadne_Node lookup(String label);
+
+
+}
--- /dev/null
+// NodeList.java
+package com.ReasoningTechnology.Ariadne;
+import java.util.ArrayList;
+
+public class Ariadne_NodeList extends ArrayList<Ariadne_Node> {
+ // Constructor
+ public Ariadne_NodeList(){
+ super();
+ }
+}
<ul>
<li>Yield a node from the list (one at a time).</li>
<li>If the list becomes empty, remove it from <code>list_of__opened_incomplete_child_list</code>.</li>
- <li>Print the node.</li>
+ <li>queue the node as the read value.</li>
<li>If the node has its own child list, add it to <code>list_of__unopened_node</code>.</li>
</ul>
</li>
private static final Ariadne_Test test = Ariadne_Test.make("Ariadne_SRM<BigInteger>::");
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
}
@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);
}
}
--- /dev/null
+#!/bin/bash
+java Example_CountingNumber
--- /dev/null
+/*
+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());
+
+ }
+}
+++ /dev/null
-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<ExampleResource> 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 );
- }
-
-}
--- /dev/null
+#!/bin/bash
+java Example_IndexTree_0
-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<BigInteger[]> 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();
}
}
--- /dev/null
+#!/bin/bash
+java Example_IndexTree_Diagonal_SRM
--- /dev/null
+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<BigInteger[]> 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();
+ }
+}
--- /dev/null
+#!/bin/bash
+java Example_SRMI_Array
public class Example_SRMI_Array {
public static void main( String[] args ) {
+ /*
+
// Create a list
- List<String> labels = Arrays.asList( "A" ,"B" ,"C" ,"D" );
+ List<String> label_list = Arrays.asList( "A" ,"B" ,"C" ,"D" );
// Attach SRMI to the list
- Ariadne_SRMI_Array<String> srm = Ariadne_SRMI_Array.attach( labels );
+ Ariadne_SRMI_Array<String> srm = Ariadne_SRMI_Array.make( label_list );
// Use the SRMI
System.out.println( "Topology: " + srm.topology() );
// Final item
System.out.println( "Reading: " + srm.read() );
System.out.println( "Status: " + srm.status() );
+
+ */
}
}
+++ /dev/null
-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()
- );
- }
- }
-}
-
+++ /dev/null
-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<Integer> srm = Ariadne_SRM.make(delegate);
-
- // Define a list to iterate over
- List<Integer> 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());
- }
-}
--- /dev/null
+#!/bin/bash
+java Example_SRM_List
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<String> labels = new List<>();
- labels.add( "A" );
- labels.add( "B" );
- labels.add( "C" );
+ LinkedList<String> labels = new LinkedList<>();
+ labels.add("A");
+ labels.add("B");
+ labels.add("C");
- // Attach SRMI to the linked list
- Ariadne_SRMI_List<String> srm = Ariadne_SRMI_List.attach( labels );
+ // Attach SRM to the linked list
+ Ariadne_SRM_List<String> 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());
}
}
--- /dev/null
+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<BigInteger[]> {
+
+ private final Ariadne_SRM_List<Ariadne_IndexTree_Node> list_of__unopened_node;
+ private final Ariadne_SRM_List<Ariadne_SRM_List<Ariadne_IndexTree_Node>> list_of__opened_incomplete_child_list;
+ private final Ariadne_SRM_List<BigInteger[]> 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<Ariadne_IndexTree_Node> 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<Ariadne_IndexTree_Node> 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();
+ }
+}
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<T> {
+public interface Ariadne_Graph<TLabel> {
- // One or more nodes for starting graph traversals
- Ariadne_SRM<T> start();
+ // returns list of TLabel
+ Ariadne_SRM<TLabel> start();
- // Method to look up a node by label
- Ariadne_Node<T> lookup(T label);
+ // lookup a Node by label
+ Ariadne_Node<TLabel> lookup(TLabel label);
}
+++ /dev/null
-/*
-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<T> implements Ariadne_ResourceIdentity<T>{
-
- private final String namespace;
- private final AtomicInteger counter;
- private final ConcurrentHashMap<String ,ResourceIdentity> 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() + "}";
- }
-
-}
--- /dev/null
+package com.ReasoningTechnology.Ariadne;
+
+import java.math.BigInteger;
+
+public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM<BigInteger[]> {
+
+ 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);
+ }
+
+}
public class Ariadne_IndexTree_Graph implements Ariadne_Graph<BigInteger[]>{
@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
}
}
+
}
@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
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-import java.math.BigInteger;
-
-public class Ariadne_IndexTree_SRM extends Ariadne_SRM<BigInteger[]> {
-
- 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;
- }
-
-}
+++ /dev/null
-/*
-
-
-*/
-
-
-package com.ReasoningTechnology.Ariadne;
-
-public interface Ariadne_LockManager{
- Ariadne_LockManagerDelegate<T> single_thread(Object resource);
- Ariadne_LockManagerDelegate<T> multiple_thread(Object resource);
-}
+++ /dev/null
-package com.ReasoningTechnology.Ariadne;
-
-public interface Ariadne_LockManagerDelegate{
- void request();
- void relinquish();
-}
import java.util.HashMap;
import java.util.HashSet;
-public class Ariadne_Node<T> extends HashMap<String, Object> {
+public class Ariadne_Node<TLabel> extends HashMap<String, Object> {
// Owned by the class
- public static <T> Ariadne_Node<T> make(T label) {
- return new Ariadne_Node<>(label) ;
+ public static <TLabel> Ariadne_Node<TLabel> make(TLabel label) {
+ return new Ariadne_Node<>(label);
}
// Data owned by the instance
- private final T label ;
- private final HashSet<Ariadne_Token> markSet ;
- private static final String NEIGHBOR_PROPERTY_NAME = "neighbor_property" ;
+ private final TLabel label;
+ private final HashSet<Ariadne_Token> 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<T> neighbor() {
- return Ariadne_SRM.make() ;
+ public Ariadne_SRM<TLabel> 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
return "Ariadne_Node{"
+ "label=" + label
+ " ,markSet=" + markSet
- + "}" ;
+ + "}";
}
}
/*
-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<T>{
+public class Ariadne_SRM<TElement> {
+
+ public static <TElement> Ariadne_SRM<TElement> 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
,RIGHTMOST
;
}
-
- private final LockManagerDelegate<T> delegate;
-
- public static <T> Ariadne_SRM<T> make(LockManagerDelegate<T> delegate){
- if(delegate == null){
- throw new IllegalArgumentException("Ariadne_SRM::make delegate cannot be null.");
- }
- return new Ariadne_SRM<>(delegate);
- }
-
- private Ariadne_SRM(LockManagerDelegate<T> 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.");
}
+
}
}
@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;}
super();
}
- public void mount(List<T> 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()){
@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());
}
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.");
}
+++ /dev/null
-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<Ariadne_Node> start();
- public Ariadne_StepRightMachine<Ariadne_Node> traverse();
- public Ariadne_Node lookup(String label);
-
-
-}
+++ /dev/null
-// NodeList.java
-package com.ReasoningTechnology.Ariadne;
-import java.util.ArrayList;
-
-public class Ariadne_NodeList extends ArrayList<Ariadne_Node> {
- // Constructor
- public Ariadne_NodeList(){
- super();
- }
-}
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."