static void Main(string[] args) { Console.WriteLine("Hello World!"); One2OneChannel channel1 = Channel.one2one(); One2OneChannel channel2 = Channel.one2one(); AltingExample altingExample = new AltingExample(channel1.In(), channel2.In()); Numbers num = new Numbers(channel1.Out()); Numbers num2 = new Numbers(channel2.Out()); //Alting input example IamCSProcess[] altingInputExample = { num, num2, altingExample }; new CSPParallel(altingInputExample).run(); //================ Alting Output Example ========================= //AltingOutputExample altingOutput = new AltingOutputExample((AltingChannelOutput)channel1.Out(), (AltingChannelOutput)channel2.Out()); //IamCSProcess[] altingOutputExample = { num, num2, altingOutput }; //Alting Gadget example ============================ //AltingBarrier altingBarrier = new AltingBarrier(); //new CSPParallel(altingOutputExample).run(); Console.ReadKey(); }
/** * Initializes all the attributes to necessary values. * Channels are created using the static factory in the * <code>ChannelServer</code> inteface. * * Constructor for One2OneConnectionImpl. */ public Any2AnyConnectionImpl() : base() { chanToServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanFromServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanClientSynch = StandardChannelFactory.getDefaultInstance().createAny2One(new CSPBuffer(1)); chanServerSynch = StandardChannelFactory.getDefaultInstance().createAny2One(new CSPBuffer(1)); }
static void Main(string[] args) { Console.WriteLine("How many Philosophers?\t"); int philosophers = Int32.Parse(Console.ReadLine()); Any2OneChannel service = Channel.any2one(); One2AnyChannel deliver = Channel.one2any(); One2OneChannel supply = Channel.one2one(); List <IamCSProcess> network = new List <IamCSProcess>(); Philosopher[] philosopherList = new Philosopher[philosophers]; for (int i = 0; i < philosophers; i++) { philosopherList.SetValue(new Philosopher(philosopherId: i, service: service.Out(), deliver: deliver.In()), i); network.Add(philosopherList[i]); } network.Add(new QueuingServery(service: service.In(), deliver: deliver.Out(), supply: supply.In())); network.Add(new Kitchen(supply: supply.Out())); new CSPParallel(network.ToArray()).run(); }
/** * Initializes all the attributes to necessary values. * Channels are created using the static factory in the * <code>ChannelServer</code> inteface. * * Constructor for One2OneConnectionImpl. */ public Any2OneConnectionImpl() : base() { chanToServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanFromServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanSynch = StandardChannelFactory.getDefaultInstance().createAny2One(new CSPBuffer(1)); //create the server object - client object created when accessed connectionServer = new AltingConnectionServerImpl(chanToServer.In(), chanToServer.In()); }
/** * Constructs and returns an array of <code>One2OneChannel</code> * objects. * * @param n the size of the array of channels. * @return the array of channels. * * @see jcsp.lang.ChannelArrayFactory#createOne2One(int) */ public One2OneChannel[] createOne2One(int n) { One2OneChannel[] toReturn = new One2OneChannel[n]; for (int i = 0; i < n; i++) { toReturn[i] = createOne2One(); } return(toReturn); }
/** * Constructs and returns an array of <code>One2OneChannel</code> * objects with a given buffering behaviour. * * @param n the size of the array of channels. * @param buffer the buffer implementation to use. * @return the array of channels. * * @see jcsp.lang.ChannelArrayFactory#createOne2One(int) */ public One2OneChannel[] createOne2One(ChannelDataStore buffer, int n) { One2OneChannel[] toReturn = new One2OneChannel[n]; for (int i = 0; i < n; i++) { toReturn[i] = createOne2One(buffer); } return(toReturn); }
public static One2OneChannel[] one2oneArray(int size) { One2OneChannel[] r = new One2OneChannel[size]; for (int i = 0; i < size; i++) { r[i] = one2one(); } return(r); }
public static One2OneChannel[] one2oneArray(int size, ChannelDataStore data, int immunity) { One2OneChannel[] r = new One2OneChannel[size]; for (int i = 0; i < size; i++) { r[i] = one2one(data, immunity); } return(r); }
/** * Gets a channel input end for receiving Link Lost events. * * @return A input end for receiving Link Lost Events. */ /*synchronized*/ internal AltingChannelInput getLinkLostEventChannel() { // Create a new infinitely buffered one to one channel One2OneChannel eventChan = Channel.one2one(new InfiniteBuffer()); // Add the output end to the list of event channels eventChans.Add(eventChan.Out()); // Return the input end return(eventChan.In()); }
public void run() { One2OneChannel console = Channel.one2one(); Chef chef = new Chef(supply: supply, toConsole: console.Out()); GConsole chefConsole = new GConsole(toConsole: console.In(), frameLabel: "Chef"); IamCSProcess[] network = { chef, chefConsole }; new CSPParallel(network).run(); }
static void Main(string[] args) { One2OneChannel N2P = Channel.one2one(); IamCSProcess[] testList = { new Numbers(outChannel: N2P.Out()), new GPrint(inChannel: N2P.In(), heading: "Numbers", delay: 1000) }; new CSPParallel(testList).run(); }
/** * Initializes all the attributes to necessary values. * Channels are created using the static factory in the * <code>ChannelServer</code> interface. * * Constructor for One2OneConnectionImpl. */ public One2AnyConnectionImpl() : base() { chanToServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanFromServer = StandardChannelFactory.getDefaultInstance().createOne2One(new CSPBuffer(1)); chanSynch = StandardChannelFactory.getDefaultInstance().createAny2One(new CSPBuffer(1)); //create the client and server objects altingClient = new AltingConnectionClientImpl(chanFromServer.In(), chanToServer.Out(), chanToServer.Out(), chanFromServer.Out()); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); One2OneChannel regularTimer = Channel.one2one(); Regular regular = new Regular(regularTimer.Out(), 1, 1000); Consumer consumer = new Consumer(regularTimer.In()); IamCSProcess[] network = { regular, consumer }; new CSPParallel(network).run(); Console.ReadKey(); }
public void run() { One2OneChannel console = Channel.one2one(); QueuingCanteen servery = new QueuingCanteen(service: service, deliver: deliver, supply: supply, toConsole: console.Out()); GConsole serveryConsole = new GConsole(toConsole: console.In(), frameLabel: "Queuing Servery"); IamCSProcess[] network = { servery, serveryConsole }; new CSPParallel(network).run(); }
public void run() { One2OneChannel a = Channel.createOne2One(); One2OneChannel b = Channel.createOne2One(); One2OneChannel c = Channel.createOne2One(); new CSPParallel( new IamCSProcess[] { new Delta2(a.In(), b.Out(), outChannel), new Successor(b.In(), c.Out()), new Prefix(0, c.In(), a.Out()) }) .run(); }
public void run() { One2OneChannel console = Channel.one2one(); PhilosopherBehaviour philosopher = new PhilosopherBehaviour(service: service, deliver: deliver, toConsole: console.Out(), id: philosopherId); GConsole philosopherConsole = new GConsole(toConsole: console.In(), frameLabel: "Philosopher " + philosopherId); IamCSProcess[] network = { philosopher, philosopherConsole }; new CSPParallel(network).run(); }
static void Main(string[] args) { One2OneChannel a = Channel.one2one(); One2OneChannel b = Channel.one2one(); One2OneChannel reset = Channel.one2one(); new CSPParallel( new IamCSProcess[] { new Numbers(outChannel: a.Out()), new Regulator2Timers(a.In(), b.Out()), new GPrint(inChannel: b.In(), heading: "Numbers", delay: 1000) } ).run(); }
/** * The main body of this process. */ public void run() { /*final*/ One2OneChannel a = Channel.createOne2One(); /*final*/ One2OneChannel b = Channel.createOne2One(); /*final*/ One2OneChannel c = Channel.createOne2One(); new CSPParallel(new IamCSProcess[] { new Prefix(0, b.In(), c.Out()), new Delta2(a.In(), Out, b.Out()), new Plus(In, c.In(), a.Out()) }).run(); }
/** * Creates a new One2NetChannel by connecting to an already created NetChannelInput * * @param loc * The location of the NetChannelInput * @param immunity * The immunity level of the channel * @param filter * The filter used to encode outgoing messages * @return A new One2NetChannel * @//throws JCSPNetworkException * Thrown if the connection to the remote Node fails */ internal static One2NetChannel create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter) ////throws JCSPNetworkException { // Create the channel data structure ChannelData data = new ChannelData(); // Create the channel linking this to the Link level. This channel is the one used to receive acknowledgement // messages One2OneChannel chan = Channel.one2one(new InfiniteBuffer()); data.toChannel = chan.Out(); // Set state of channel data.state = ChannelDataState.OK_OUTPUT; // Register channel ChannelManager.getInstance().create(data); // We now need to create the connection to the input end of the channel ChannelOutput toLink; // Check if this is a local link, and if so connect directly to the input channel if (loc.getNodeID().equals(Node.getInstance().getNodeID())) { toLink = ChannelManager.getInstance().getChannel(loc.getVCN()).toChannel; return(new One2NetChannel(chan.In(), toLink, null, data, loc, immunity, filter)); } // Connect to remote node if necessary Link link = LinkManager.getInstance().requestLink(loc.getNodeID()); // Check if an existing connection exists if (link == null) { // We are not connected. Connect to remote Node. link = LinkFactory.getLink(loc.getNodeID()); } // Get the connection to the Link. toLink = link.getTxChannel(); // Return new channel return(new One2NetChannel(chan.In(), toLink, link, data, loc, immunity, filter)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); One2OneChannel RU2RN = Channel.one2one(); One2OneChannel RN2Conv = Channel.one2one(); One2OneChannel Conv2FD = Channel.one2one(); One2OneChannel FD2GC = Channel.one2one(); IamCSProcess[] RNprocList = { new ResetNumbers(resetChannel: RU2RN.In(), initialValue: 1000, outChannel: RN2Conv.Out()), new GObjectToConsoleString(inChannel: RN2Conv.In(), outChannel: Conv2FD.Out()), new FixedDelay(delayTime: 200, In: Conv2FD.In(), Out: FD2GC.Out()), //new GConsole(toConsole: FD2GC.In(), // frameLabel: "Reset Numbers Console") }; One2OneChannel RU2GC = Channel.one2one(); One2OneChannel GC2Conv = Channel.one2one(); One2OneChannel Conv2RU = Channel.one2one(); One2OneChannel RU2GCClear = Channel.one2one(); IamCSProcess[] RUprocList = { new ResetUser(resetValue: RU2RN.Out(), toConsole: RU2GC.Out(), fromConverter: Conv2RU.In(), toClearOutput: RU2GCClear.Out()), new GConsoleStringToInteger(inChannel: GC2Conv.In(), outChannel: Conv2RU.Out()), //new GConsole(toConsole: RU2GC.In(), // fromConsole: GC2Conv.Out(), // clearInputArea: RU2GCClear.In(), // frameLabel: "Reset Value Generator") }; //new CSPParallel(RNprocList + RUprocList).run(); Console.ReadKey(); }
static void Main(string[] args) { One2OneChannel[] a = Channel.one2oneArray(5); One2OneChannel b = Channel.one2one(); new CSPParallel( new IamCSProcess[] { new Regular(a[0].Out(), 0, 5), new Regular(a[1].Out(), 1, 5), new Regular(a[2].Out(), 2, 5), new Regular(a[3].Out(), 3, 5), new Regular(a[4].Out(), 4, 5), new FairPlexTime(Channel.getInputArray(a), b.Out(), 10000), new Printer(b.In(), "FairPlexTimeTest ==> ", "\n") } ).run(); }
static void Main(string[] args) { One2OneChannel a = Channel.one2one(); One2OneChannel b = Channel.one2one(); One2OneChannel reset = Channel.one2one(); var process = new SupportingProcess(reset); new CSPParallel( new IamCSProcess[] { new Variate(a.Out(), 5000, 10, 2), new Regulate(a.In(), reset.In(), b.Out(), 500), new Printer(b.In(), "RegulateTest ==> ", "\n"), process } ).run(); }
static void Main(string[] args) { Console.WriteLine("Hello World! TEST REGULATE"); One2OneChannel a = Channel.createOne2One(); One2OneChannel b = Channel.createOne2One(); One2OneChannel c = Channel.createOne2One(); One2OneChannel reset = Channel.createOne2One(new OverWriteOldestBuffer(1)); Numbers num = new Numbers(a.Out()); FixedDelay fixedDelay = new FixedDelay(250, a.In(), b.Out()); Regulate regulate = new Regulate(b.In(), reset.In(), c.Out(), 1000); LoopsProcess loops = new LoopsProcess(c.In(), reset.Out()); IamCSProcess[] network = { num, fixedDelay, regulate, loops }; new CSPParallel(network).run(); Console.ReadKey(); }
/*public static String TITLE = "CommsTime"; * public static String DESCR = * "Test of communication speed between JCSP processes. Based on OCCAM CommsTime.occ by Peter Welch, " + * "University of Kent at Canterbury. Ported into Java by Oyvind Teig. Now using the JCSP library.\n" + * "\n" + * "A small network of four processes is created which will generate a sequence of numbers, measuring " + * "the time taken to generate each 10000. This time is then divided to calculate the time per iteration, " + * "the time per communication (one integer over a one-one channel) and the time for a context switch. " + * "There are four communications per iteration and two context switches per communication. This test " + * "forms a benchmark for the for the overheads involved.\n" + * "\n" + * "This version uses a PARallel delta2 component, so includes the starting and finishing of one extra" + * "process per loop.";*/ public static void Main(string[] args) { int nLoops = 10000; Console.WriteLine(nLoops + " loops ...\n"); One2OneChannel P2D = Channel.one2one(); One2OneChannel D2S = Channel.one2one(); One2OneChannel S2P = Channel.one2one(); One2OneChannel D2C = Channel.one2one(); new CSPParallel( new IamCSProcess[] { new Prefix(0, S2P.In(), P2D.Out()), new Delta2(P2D.In(), D2C.Out(), D2S.Out()), new Successor(D2S.In(), S2P.Out()), new Consume(nLoops, D2C.In()) } ).run(); }
static void Main(string[] args) { One2OneChannel data = Channel.one2one(); One2OneChannel timedData = Channel.one2one(); One2OneChannel scaledData = Channel.one2one(); One2OneChannel oldScale = Channel.one2one(); One2OneChannel newScale = Channel.one2one(); One2OneChannel pause = Channel.one2one(); Numbers num = new Numbers(data.Out()); FixedDelay fixedDelay = new FixedDelay(1000, data.In(), timedData.Out()); Scale scale = new Scale(inChannel: timedData.In(), outChannel: scaledData.Out(), factor: oldScale.Out(), suspend: pause.In(), injector: newScale.In(), multiplier: 2, scaling: 2); Controller controller = new Controller(testInterval: 11000, computeInterval: 3000, addition: 1, factor: oldScale.In(), suspend: pause.Out(), injector: newScale.Out()); GPrint gPrint = new GPrint(inChannel: scaledData.In(), heading: "Scaled_Data", delay: 1000); IamCSProcess[] network = { num, fixedDelay, scale, controller, gPrint }; new CSPParallel(network).run(); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Numbers started!"); Console.WriteLine("Please enter IP address for this node."); var numbersNodeIP = Console.ReadLine(); Console.WriteLine("Please enter IP address for Consume."); var consumeNodeIP = Console.ReadLine(); var numbersNodeAddr = new TCPIPNodeAddress(numbersNodeIP, 3000); Node.getInstance().init(numbersNodeAddr); var consumeNodeAddr = new TCPIPNodeAddress(consumeNodeIP, 3300); var numbers2network = NetChannel.one2net(consumeNodeAddr, 50); Console.WriteLine("network2consume location = " + numbers2network.getLocation().ToString()); Console.WriteLine("Sending signal to Consume..."); numbers2network.write(0); // signal from the numbers; Console.WriteLine("Sent signal to Consume"); //====================== Running the test One2OneChannel P2D = Channel.one2one(); One2OneChannel D2S = Channel.one2one(); One2OneChannel S2P = Channel.one2one(); new CSPParallel( new IamCSProcess[] { new Prefix(0, S2P.In(), P2D.Out()), new Delta2(P2D.In(), numbers2network, D2S.Out()), new Successor(D2S.In(), S2P.Out()), } ).run(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); One2OneChannel[] a = Channel.one2oneArray(5); One2OneChannel b = Channel.one2one(); new CSPParallel( new IamCSProcess[] { new Regular(a[0].Out(), 1, 1000), new Regular(a[1].Out(), 2, 2000), new Regular(a[2].Out(), 3, 3000), new Regular(a[3].Out(), 4, 4000), new Regular(a[4].Out(), 5, 5000), new Polling(a[0].In(), a[1].In(), a[2].In(), a[3].In(), a[4].In(), b.Out()), new Printer(b.In(), "PollingTest ==> ", "\n") } ).run(); Console.ReadKey(); }
public void run() { One2OneChannel a = Channel.one2one(); One2OneChannel b = Channel.one2one(); One2OneChannel c = Channel.one2one(); IamCSProcess[] testList = { new ResetPrefix(prefixValue: initialValue, outChannel: a.Out(), inChannel: c.In(), resetChannel: resetChannel), //Used plugNplay Delta2 instead of creating GCopy new Delta2(In: a.In(), Out1: outChannel, Out2: b.Out()), new Successor(In: b.In(), Out: c.Out()) }; new CSPParallel(testList).run(); }
static void Main(string[] args) { int n_philosophers = 5; Any2OneChannel service = Channel.any2one(); One2OneChannel deliver = Channel.one2one(); One2OneChannel supply = Channel.one2one(); Philosopher[] philosopher = new Philosopher[n_philosophers]; for (int i = 0; i < n_philosophers; i++) { philosopher[i] = new Philosopher(i, service.Out(), deliver.In()); } IamCSProcess[] network = { new Clock(), new Canteen(service.In(),supply.In(), deliver.Out()), new Chef(supply.Out()), new CSPParallel(philosopher) }; new CSPParallel(network).run(); }
static void Main(string[] args) { // synchronisation components AltingBarrier[] stable = AltingBarrier.create(10); var elfGroups = Bucket.create(4); // Santa to Vestibule Channels One2OneChannel openForBusiness = Channel.createOne2One(); One2OneChannel consultationOver = Channel.createOne2One(); //reindeer channels Any2OneChannel harness = Channel.createAny2One(); One2AnyChannel harnessed = Channel.createOne2Any(); One2AnyChannel returned = Channel.createOne2Any(); One2OneChannel[] unharness = Channel.createOne2One(9); ChannelOutputList unharnessList = new ChannelOutputList(unharness); // elf channels, including Vestibule channels Any2OneChannel needToConsult = Channel.createAny2One(); One2AnyChannel joinGroup = Channel.createOne2Any(); Any2OneChannel consult = Channel.createAny2One(); Any2OneChannel negotiating = Channel.createAny2One(); One2OneChannel[] consulting = Channel.createOne2One(10); One2OneChannel[] consulted = Channel.createOne2One(10); ChannelOutputList consultingList = new ChannelOutputList(consulting); ChannelOutputList consultedList = new ChannelOutputList(consulted); List <IamCSProcess> grottoList = new List <IamCSProcess>(); Reindeer[] herd = new Reindeer[9]; for (int i = 0; i < 9; i++) { herd[i] = new Reindeer(number: i, stable: stable[i], harness: harness.Out(), harnessed: harnessed.In(), returned: returned.In(), unharness: unharness[i].In(), holidayTime: 15000 ); grottoList.Add(herd[i]); } Elf[] elves = new Elf[9]; IamCSProcess[] elvesNetwork = new IamCSProcess[8]; for (int i = 0; i < 9; i++) { elves[i] = new Elf(number: i, groups: elfGroups, needToConsult: needToConsult.Out(), joinGroup: joinGroup.In(), consult: consult.Out(), consulting: consulting[i].In(), negotiating: negotiating.Out(), consulted: consulted[i].In(), workingTime: 1000 ); grottoList.Add(elves[i]); } Santa santa = new Santa(openForBusiness: openForBusiness.Out(), consultationOver: consultationOver.Out(), harness: harness.In(), harnessed: harnessed.Out(), returned: returned.Out(), unharnessList: unharnessList, stable: stable[9], consult: consult.In(), consulting: consultingList, negotiating: negotiating.In(), consulted: consultedList, deliveryTime: 1000, consultationTime: 1000 ); Vestibule vestibule = new Vestibule(groups: elfGroups, needToConsult: needToConsult.In(), joinGroup: joinGroup.Out(), openForBusiness: openForBusiness.In(), consultationOver: consultationOver.In() ); grottoList.Add(santa); grottoList.Add(vestibule); IamCSProcess[] grotto = grottoList.ToArray(); new CSPParallel(grotto).run(); }