Exemplo n.º 1
0
        public void Initialize(int memSize)
        {
            MemorySize = memSize;

            for (int i = 0; i < MemorySize; i++)
            {
                Memory.Add(new MemoryBlock()
                {
                    ProcessId  = 0,
                    IsAssigned = false,
                    IsEnd      = false,
                    IsStart    = false
                });
            }


            MemoryInitEventArgs arg = new MemoryInitEventArgs
            {
                MemoryAlgorithmName = "Best Fit",
                NumberOfBlocks      = MemorySize,
                Memory = this.Memory
            };

            BlockFit firstblock = new BlockFit();

            firstblock.start_pos   = 0;
            firstblock.ID          = 0;
            firstblock.blockLength = MemorySize;
            avail.Add(firstblock);


            OnInitialize(arg);
        }
Exemplo n.º 2
0
        public override string Part1(string input)
        {
            var lines = input.Lines();

            var mask = new Mask("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

            var memory = new Memory();

            foreach (var line in lines)
            {
                var parts = line.Split();

                if (line.StartsWith("mask"))
                {
                    mask = new Mask(parts[2]);
                }
                else if (line.StartsWith("mem"))
                {
                    var lhs     = parts[0].Split('[', ']');
                    var address = int.Parse(lhs[1]);
                    var value   = int.Parse(parts[2]);

                    var maskedValue = mask.Apply(value);

                    memory.Add(address, maskedValue);
                }
            }

            return(memory.Sum().ToString());
        }
Exemplo n.º 3
0
 private void ExtendMemory(int goal)
 {
     for (int k = Memory.Count + 1; k <= goal + 1; k++)
     {
         Memory.Add(0);
     }
 }
Exemplo n.º 4
0
        public void Part1Initialise()
        {
            if (Memory != null)
            {
                Memory.Clear();
            }

            foreach (ICommand command in InitProgram)
            {
                if (command is BitMask)
                {
                    var bitMaskCommand = command as BitMask;
                    CurrentBitMask = bitMaskCommand.BinaryStringValue;
                }

                if (command is MemoryCommand)
                {
                    var memoryCommand = command as MemoryCommand;

                    int address = memoryCommand.Address;

                    string maskifiedBinaryString = MaskifyValue(memoryCommand.BinaryStringValue);
                    double value = IntifyBinaryStringValue(maskifiedBinaryString);

                    if (Memory.ContainsKey(address))
                    {
                        Memory[address] = value;
                    }
                    else
                    {
                        Memory.Add(memoryCommand.Address, value);
                    }
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Checks to see if we have a memory of the new target
 /// If we do not, then we create one
 /// </summary>
 /// <param name="target">The Object the AI is seeking</param>
 private void MakeNewMemory(GameObject target)
 {
     if (!myMemory.ContainsKey(target))
     {
         targets.Add(target);
         myMemory.Add(target, new MemoryProps());
     }
 }
Exemplo n.º 6
0
        public Task3_FindTorrents(MyNamedTasks Tasks)
            : base(Tasks, "Task3_FindTorrents")
        {
            var NamedTasks = Tasks;

            this.Description = @"
This task will fetch torrent links and spawn work for them. 
This could be extended to support multiple torrent services. 
Default implmentation will assume <a href='http://piratebay.org/'>piratebay</a>.

This task should not run when there is work for Task4_PrepareMedia 
			"            ;

            this.YieldWork =
                (Task, Input) =>
            {
                // if we fail, we this work item will not be retried
                Input.Delete();

                var DismissedItems = 0;

                BasicPirateBaySearch.Search(
                    k => Memory.Contains(k.Hash),
                    (entry, deferred) =>
                {
                    if (deferred)
                    {
                        DismissedItems++;
                        return;
                    }

                    Memory.Add(entry.Hash);

                    AppendLog("output " + entry.Name);

                    var c = NamedTasks.Task4_PrepareMedia.AddWork(5, entry.Hash).ToFieldBuilder();

                    FileMappedField
                    TorrentName     = c[entry.Name],
                    TorrentLink     = c[entry.TorrentLink],
                    TorrentSize     = c[entry.Size],
                    TorrentComments = c[entry.Link];

                    c.ToFile();
                }
                    );

                if (DismissedItems > 0)
                {
                    AppendLog("dismissed " + DismissedItems);
                }

                return(delegate
                {
                    // this will be called if the task is still active
                });
            };
        }
Exemplo n.º 7
0
        // Ben Thornhill
        public void InitializeMemory()
        {
            Memory.Clear();

            for (int i = 0; i < MemorySize; i++)
            {
                Memory.Add("0000");
            }
        }
Exemplo n.º 8
0
 static void tryAddToMemory(Collectable item)
 {
     try {
         shortTermMemory.Add(item.ID, new ObjectState());
     }
     catch (System.ArgumentException) {
         Debug.LogError("A chave [ " + item.ID + " ] para ' " + item.name + " ' já existe no dicionario");
     }
 }
        public long ReadMemory(int address)
        {
            if (!Memory.ContainsKey(address))
            {
                Memory.Add(address, 0);
            }

            return(Memory[address]);
        }
Exemplo n.º 10
0
        public override string AddClass(ClassDetails classDetails, string parentHash)
        {
            Class @class = new(classDetails.Modifier, classDetails.Name, new ModelProperties(classDetails.IsModel, classDetails.ModelLocation), parentHash);

            @class.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@class))));
            Memory.Add(@class);

            return(@class.Hash);
        }
Exemplo n.º 11
0
 protected override void OnTextChanged(EventArgs e)
 {
     saved = false;
     base.OnTextChanged(e);
     //CurrentText = Text;
     MakeAutoCompletion(true);
     CheckWords();
     Memory.Add(Text);
     //autoCompletion.Focus();
 }
Exemplo n.º 12
0
        internal void UpdateMemorySize(ulong size)
        {
            // Geth's approach to memory trace is to show empty memory spaces on entry for the values that are being set by the operation
            int missingChunks = (int)((size - (ulong)Memory.Count * EvmPooledMemory.WordSize) / EvmPooledMemory.WordSize);

            for (int i = 0; i < missingChunks; i++)
            {
                Memory.Add("0000000000000000000000000000000000000000000000000000000000000000");
            }
        }
Exemplo n.º 13
0
        public Sample AddSample(Sample sample)
        {
            Memory.Add(sample);
            if (Memory.Count > MemoryCapacity - 1)
            {
                Memory.RemoveAt(0);
            }

            TuneFilter();

            return(Filter.AddSample(sample));
        }
Exemplo n.º 14
0
            public Life(List <Life> world, double X, double Y, List <LayerConfig> newgen = null, Life parent = null)
            {
                x  = X;
                y  = Y;
                pL = pR = pB = pT = 0.0;
                sL = sR = sB = sT = 0.0;
                network.AddLayer(new BasicLayer(null, true, 4)); //создание простой многослойной нейронной сети

                if (newgen == null)
                {
                    int maxlayers = 3 + rnd.Next(15);
                    for (int i = 0; i < maxlayers; i++)
                    {
                        bool bias  = rnd.NextDouble() >= 0.5;
                        var  layer = new LayerConfig((byte)rnd.Next(0, 16), bias, rnd.Next(100) + 10);
                        genotype.Add(layer);
                    }
                }
                else
                {
                    genotype = Mutate(newgen);
                }

                AddLayers(genotype);
                if (parent != null)
                {
                    for (int i = 0; i < parent.Memory.Count; i++)
                    {
                        if (rnd.NextDouble() > 0.5)
                        {
                            Memory.Add(parent.Memory[i]);
                            MemorySense.Add(parent.MemorySense[i]);
                        }
                    }
                }
                //network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSoftMax(), false, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSoftMax (), true, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSoftMax(), false, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSoftMax(), true, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationStep (), false, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationStep(), true, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationStep(), false, rnd.Next(100) + 10));
                //network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, rnd.Next(100) + 10));
                network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 4));

                network.Structure.FinalizeStructure();
                network.Reset();
                World = world;
            }
Exemplo n.º 15
0
        public override string AddField(FieldDetails fieldDetails, string parentHash)
        {
            var type = fieldDetails.Type;

            TypeMapper(ref type);

            Field field = new(fieldDetails.Modifier, type, fieldDetails.Name, parentHash);

            field.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(field))));
            Memory.Add(field);

            return(field.Hash);
        }
Exemplo n.º 16
0
        private void UpdateMemory(string n)
        {
            ulong address = ulong.Parse(Regex.Matches(n, @"\[\d+\]").First().ToString().Replace("[", "").Replace("]", ""));

            if (Memory.ContainsKey(address))
            {
                Memory[address] = ApplyMask(n.Split("=").ElementAt(1).Trim());
            }
            else
            {
                Memory.Add(address, ApplyMask(n.Split("=").ElementAt(1).Trim()));
            }
        }
Exemplo n.º 17
0
        public override string AddField(FieldDetails fieldDetails, string parentHash)
        {
            var type = fieldDetails.Type;

            TypeMapper(ref type);

            Property property = new(type, fieldDetails.Name, parentHash);

            property.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(property))));
            Memory.Add(property);

            return(property.Hash);
        }
Exemplo n.º 18
0
        public override string AddExpression(ExpressionDetails expressionDetails, string parentHash, List <string> modelTypes = null)
        {
            var statement = expressionDetails.Statement;

            StringMapper(ref statement);

            Expression expression = new(statement, parentHash);

            expression.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(expression))));
            Memory.Add(expression);

            return(expression.Hash);
        }
Exemplo n.º 19
0
        public override string AddMethod(MethodDetails methodDetails, string parentHash)
        {
            var parameters = methodDetails.Parameters;

            StringMapper(ref parameters);

            Function function = new(methodDetails.Identifier, methodDetails.Modifier, string.Empty, parameters, methodDetails.ReturnType, parentHash);

            function.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(function))));
            Memory.Add(function);

            return(function.Hash);
        }
Exemplo n.º 20
0
        public CellProcessorBase(Memory memory, CellOperators operators) : base(memory)
        {
            TestStatus          = new TestStatus();
            CallStack           = new CallStack();
            this.operators      = operators;
            operators.Processor = this;

            Memory.GetItem <Symbols>();
            Memory.GetItem <Procedures>();

            Memory.Add(new FitEnvironment(this));
            Memory.ItemOf <FitEnvironment>().RunTest = new RunTestDefault();

            ApplicationUnderTest.AddNamespace("fitSharp.Fit.Fixtures");
        }
Exemplo n.º 21
0
 /// <summary>
 /// Rewards the agent for perfomic an action
 /// ,memorizes and learns from the experience
 /// </summary>
 /// <param name="reward">-+</param>
 public void Learn(double reward)
 {
     // perform an update on Q function
     if (this.r0 > 0 && Options.Alpha > 0)
     {
         // learn from this tuple to get a sense of how "surprising" it is to the agent
         var exp = new Experience
         {
             PreviousState  = s0,
             PreviousAction = a0,
             PreviousReward = r0,
             CurrentState   = s1,
             CurrentAction  = a1
         };
         var tderror = LearnFromExperience(exp);
         TDError = tderror; // a measure of surprise
         // decide if we should keep this experience in the replay
         if (t % Options.ExperinceAddEvery == 0)
         {
             Memory.Add(new Experience {
                 PreviousState = s0, PreviousAction = a0, PreviousReward = r0, CurrentState = s1, CurrentAction = a1
             });
             if (Options.ExperienceSize > 0 && Memory.Count > Options.ExperienceSize)
             {
                 //forget oldest
                 Memory.RemoveAt(0);
             }
         }
         this.t += 1;
         // sample some additional experience from replay memory and learn from it
         if (Options.AdaptiveLearningSteps)
         {
             var op = Memory.Count * 0.005;
             if (op > 0)
             {
                 Options.LearningSteps = op.ToInt();
             }
         }
         for (var k = 0; k < Options.LearningSteps; k++)
         {
             var ri = Tembo.RandomInt(0, Memory.Count); // todo: priority sweeps?
             var e  = Memory[ri];
             LearnFromExperience(e);
         }
     }
     this.r0 = reward; // store for next update
 }
Exemplo n.º 22
0
        /// <summary>
        /// Adds an element by key, and returns whether or not the key was new.
        /// </summary>
        internal bool Add(TKey key, TElement element)
        {
            Memory <TElement> elements;

            if (!dict.TryGetValue(key, out elements))
            {
                elements  = new Memory <TElement>();
                dict[key] = elements;
                elements.Add(element);
                return(true);
            }
            else
            {
                elements.Add(element);
                return(false);
            }
        }
Exemplo n.º 23
0
        public override string AddMethod(MethodDetails methodDetails, string parentHash)
        {
            var parameters = methodDetails.Parameters;

            StringMapper(ref parameters);

            var parameterAnchor = methodDetails.ParameterAnchor;

            StringMapper(ref parameterAnchor);

            Method method = new(methodDetails.Modifier, methodDetails.ReturnType, methodDetails.Identifier, parameters, parameterAnchor, parentHash);

            method.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(method))));
            Memory.Add(method);

            return(method.Hash);
        }
Exemplo n.º 24
0
        public override string AddConstructor(ConstructorDetails constructorDetails, string parentHash)
        {
            var parameters = constructorDetails.Parameters;

            StringMapper(ref parameters);

            var parameterAnchor = constructorDetails.ParameterAnchor;

            StringMapper(ref parameterAnchor);

            Constructor constructor = new(constructorDetails.Modifier, constructorDetails.Identifier, parameters, parameterAnchor, parentHash);

            constructor.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(constructor))));
            Memory.Add(constructor);

            return(constructor.Hash);
        }
Exemplo n.º 25
0
        private void UpdateMemoryNew(string n)
        {
            long address = long.Parse(Regex.Matches(n, @"\[\d+\]").First().ToString().Replace("[", "").Replace("]", ""));

            ulong[] allAddresses = GetAddresses(address);

            foreach (var a in allAddresses)
            {
                if (Memory.ContainsKey(a))
                {
                    Memory[a] = Convert.ToUInt64(n.Split("=").ElementAt(1).Trim());
                }
                else
                {
                    Memory.Add(a, Convert.ToUInt64(n.Split("=").ElementAt(1).Trim()));
                }
            }
        }
Exemplo n.º 26
0
        public override void Push(Experience trans)
        {
            if (trans == null)
            {
                throw new ArgumentNullException();
            }

            if (Memory.Count < Capacity)
            {
                Memory.Add(trans);
            }
            else
            {
                Memory[NextIndex] = trans;
            }

            NextIndex = (NextIndex + 1) % Capacity;
        }
Exemplo n.º 27
0
        public override string AddExpression(ExpressionDetails expressionDetails, string parentHash, List <string> modelTypes = null)
        {
            if (expressionDetails.SyntaxKind == SyntaxKind.LocalDeclarationStatement)
            {
                expressionDetails.Statement = expressionDetails.Statement.Split(" ", 2).Select((content, count) => count == 0 ? content.CheckRequiresMemorySyntax(modelTypes) : content).Aggregate((i, j) => i + " " + j);
            }

            var statement = expressionDetails.Statement;

            StringMapper(ref statement);

            Expression expression = new(statement, parentHash);

            expression.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(expression))));
            Memory.Add(expression);

            return(expression.Hash);
        }
Exemplo n.º 28
0
        public override string AddClass(ClassDetails classDetails, string parentHash)
        {
            if (classDetails.IsModel)
            {
                Struct @struct = new(classDetails.Name, new ModelProperties(classDetails.IsModel, classDetails.ModelLocation), parentHash);
                @struct.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@struct))));
                Memory.Add(@struct);

                return(@struct.Hash);
            }
            else
            {
                Contract contract = new(classDetails.Name, parentHash);
                contract.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(contract))));
                Memory.Add(contract);

                return(contract.Hash);
            }
        }
Exemplo n.º 29
0
    //
    // Methods
    //

    internal Memory Clone()
    {
        Memory image = new Memory()
        {
            Orbs               = this.Orbs,
            Playtime           = this.Playtime,
            Health             = this.Health,
            AnimatorController = this.AnimatorController,
            HasGun             = this.HasGun,
            HasHook            = this.HasHook,
            Checkpoint         = this.Checkpoint,
        };

        foreach (var item in this)
        {
            image.Add(
                item.Key,
                new ObjectState(item.Value));
        }
        return(image);
    }
Exemplo n.º 30
0
        public void Initialize(int memSize)
        {
            MemorySize = memSize;

            for (int i = 0; i < MemorySize; i++)
            {
                Memory.Add(new MemoryBlock()
                {
                    ProcessId  = 0,
                    IsAssigned = false,
                    IsEnd      = false,
                    IsStart    = false
                });
            }

            MemoryInitEventArgs arg = new MemoryInitEventArgs
            {
                MemoryAlgorithmName = "First Fit",
                NumberOfBlocks      = MemorySize,
                Memory = this.Memory
            };

            OnInitialize(arg);
        }