//private string _filePath;


        public ArtificialNeuralNetwork(LayerStructure layerStructure, TrainingParameters trainingParameters,
                                       IDataSet dataSet, IOptimizationStrategy strategy, IInitialRandomDistributionType randomDistribution)
        {
            _layerStructure          = layerStructure;
            _trainingParameters      = trainingParameters;
            DataSet                  = dataSet;
            _strategy                = strategy;
            _strategy.LayerStructure = layerStructure;
            _randomDistribution      = randomDistribution;

            CreateDataSets();

            SetWeights();
            InitPreviousDeltaWeights();

            SetBiases();
            InitPreviousDeltaBiases();


            _strategy.FetchInitialWeightsAndBiases(ref _weights, ref _biases);

            _strategy.FetchPreviousDeltaWeightsAndBiases(ref _previousDeltaWeights, ref _previousDeltaBiases);

            _savePath = Path.GetTempPath();
        }
Beispiel #2
0
 private PerceptronInitParams GetInitParamsByLayerStructure(LayerStructure layerStructure)
 {
     return(new PerceptronInitParams(
                layerStructure,
                ActivationFunction.Sigmoid,
                new TrainParams(0.1f, 0.1f)));
 }
Beispiel #3
0
        public void PerceptronWeightMatrixCountWith1HiddenLayer()
        {
            LayerStructure structure  = new LayerStructure(5, new[] { 2 }, 3);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            Assert.AreEqual(2, perceptron.Weights.Count());
        }
Beispiel #4
0
        public void PerceptronWeightMatrixesDimension()
        {
            LayerStructure   structure      = new LayerStructure(10, new [] { 4, 4 }, 7);
            Perceptron       perceptron     = new Perceptron(GetInitParamsByLayerStructure(structure));
            List <float[, ]> expectedResult = new List <float[, ]>
            {
                new float[10, 4],
                new float[4, 4],
                new float[4, 7]
            };

            bool areEqual = true;

            for (int i = 0; i < expectedResult.Count; i++)
            {
                if (expectedResult[i].GetLength(0) != perceptron.Weights[i].GetLength(0) ||
                    expectedResult[i].GetLength(1) != perceptron.Weights[i].GetLength(1))
                {
                    areEqual = false;
                    break;
                }
            }

            Assert.IsTrue(areEqual);
        }
Beispiel #5
0
        /// <summary>
        ///     Copies the selection to clipboard in PNG, Bitmap and DIB formats.
        /// </summary>
        /// <param name="layers">Layers where selection is.</param>
        public static void CopyToClipboard(Layer[] layers, Layer selLayer, LayerStructure structure, int originalImageWidth, int originalImageHeight, SerializableDocument document = null)
        {
            if (!ClipboardHelper.TryClear())
            {
                return;
            }
            if (layers.Length == 0)
            {
                return;
            }

            using Surface surface = CreateMaskedCombinedSurface(layers, structure, selLayer);
            DataObject data = new DataObject();


            //BitmapSource croppedBmp = BitmapSelectionToBmpSource(finalBitmap, selLayer, out int offsetX, out int offsetY, out int width, out int height);

            //Remove for now
            //data.SetData(typeof(CropData), new CropData(width, height, offsetX, offsetY).ToStream());

            using (SKData pngData = surface.SkiaSurface.Snapshot().Encode())
            {
                // Stream should not be disposed
                MemoryStream pngStream = new MemoryStream();
                pngData.AsStream().CopyTo(pngStream);

                data.SetData("PNG", pngStream, false); // PNG, supports transparency

                pngStream.Position = 0;
                Directory.CreateDirectory(Path.GetDirectoryName(TempCopyFilePath));
                using FileStream fileStream = new FileStream(TempCopyFilePath, FileMode.Create, FileAccess.Write);
                pngStream.CopyTo(fileStream);
                data.SetFileDropList(new StringCollection()
                {
                    TempCopyFilePath
                });
            }

            WriteableBitmap finalBitmap = surface.ToWriteableBitmap();

            data.SetData(DataFormats.Bitmap, finalBitmap, true); // Bitmap, no transparency
            data.SetImage(finalBitmap);                          // DIB format, no transparency

            // Remove pixi copying for now

            /*
             * if (document != null)
             * {
             *  MemoryStream memoryStream = new();
             *  PixiParser.Serialize(document, memoryStream);
             *  data.SetData("PIXI", memoryStream); // PIXI, supports transparency, layers, groups and swatches
             *  ClipboardHelper.TrySetDataObject(data, true);
             * }
             */

            ClipboardHelper.TrySetDataObject(data, true);
        }
Beispiel #6
0
        public void PerceptronWeightsAreChangedAfterTrainIteration()
        {
            LayerStructure structure  = new LayerStructure(9, new [] { 7 }, 5);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();

            Assert.IsFalse(true);
        }
 private Document()
 {
     SetRelayCommands();
     UndoManager            = new UndoManager();
     LayerStructure         = new LayerStructure(this);
     XamlAccesibleViewModel = ViewModelMain.Current;
     GeneratePreviewLayer();
     Layers.CollectionChanged += Layers_CollectionChanged;
     LayerStructure.Groups.CollectionChanged += Groups_CollectionChanged;
     LayerStructure.LayerStructureChanged    += LayerStructure_LayerStructureChanged;
 }
Beispiel #8
0
        public void PerceptronWeightsAreTakenIntoAccount()
        {
            LayerStructure structure  = new LayerStructure(9, new[] { 7 }, 5);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();
            float[] inputVector = new[] { 0.44f, 0.354f, 0.667f, 0, 0.454f, 0.48f, 0.456f, 0.44f, 0.456f };

            float[] outputVector = perceptron.CalculateOutput(inputVector);

            Assert.AreNotEqual(inputVector, outputVector, "Input and output vectors are same");
        }
Beispiel #9
0
        private static Surface CreateMaskedCombinedSurface(Layer[] layers, LayerStructure structure, Layer selLayer)
        {
            if (layers.Length == 0)
            {
                throw new ArgumentException("Can't combine 0 layers");
            }
            selLayer.ClipCanvas();

            Surface combined = BitmapUtils.CombineLayers(new Int32Rect(selLayer.OffsetX, selLayer.OffsetY, selLayer.Width, selLayer.Height), layers, structure);

            using SKImage snapshot = selLayer.LayerBitmap.SkiaSurface.Snapshot();
            combined.SkiaSurface.Canvas.DrawImage(snapshot, 0, 0, Surface.MaskingPaint);
            return(combined);
        }
Beispiel #10
0
        public void PerceptronOutputIsFromZeroToOne()
        {
            LayerStructure structure  = new LayerStructure(9, new[] { 6, 6 }, 5);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();
            float[] inputVector = { 0.44f, 0.354f, 0.667f, 0, 0.454f, 0.48f, 0.456f, 0.44f, 0.456f };

            float[] outputVector = perceptron.CalculateOutput(inputVector);

            int correctValuesCount = outputVector.Count(value => value > 0 && value <= 1);

            Assert.AreEqual(outputVector.Count(), correctValuesCount);
        }
Beispiel #11
0
        /// <summary>Checks the soil sample.</summary>
        /// <param name="parentSoil">The parent soil.</param>
        /// <param name="sample">The sample.</param>
        /// <param name="sowing">The sowing rule</param>
        private static void CheckSample(Soil parentSoil, Sample sample, Sow sowing)
        {
            // Do some checking of NO3 / NH4
            CheckMissingValuesAreNaN(sample.NO3);
            CheckMissingValuesAreNaN(sample.NH4);
            CheckMissingValuesAreNaN(sample.OC);
            CheckMissingValuesAreNaN(sample.EC);
            CheckMissingValuesAreNaN(sample.PH);

            if (sample.SW != null && sample.SW.Length > 0)
            {
                // Check to make sure SW is >= CLL for layers below top layer
                int cropIndex = parentSoil.Water.Crops.FindIndex(crop => crop.Name.Equals(sowing.Crop, StringComparison.CurrentCultureIgnoreCase));
                if (cropIndex != -1)
                {
                    double[] CLLVol       = parentSoil.Water.Crops[cropIndex].LL;
                    double[] CLLVolMapped = LayerStructure.MapConcentration(CLLVol, parentSoil.Water.Thickness,
                                                                            sample.Thickness, 0);

                    if (sample.SWUnits == Sample.SWUnitsEnum.Gravimetric)
                    {
                        // Sample SW is in gravimetric
                        double[] BDMapped = LayerStructure.MapConcentration(parentSoil.Water.BD, parentSoil.Water.Thickness,
                                                                            sample.Thickness, parentSoil.Water.BD.Last());
                        double[] CLLGrav = MathUtilities.Divide(CLLVolMapped, BDMapped); // vol to grav
                        double[] SWVol   = MathUtilities.Multiply(sample.SW, BDMapped);  // grav to vol
                        for (int i = 1; i < sample.Thickness.Length; i++)
                        {
                            if (SWVol[i] < CLLVolMapped[i])
                            {
                                sample.SW[i] = CLLGrav[i];
                            }
                        }
                    }
                    else
                    {
                        // Sample SW is in volumetric
                        for (int i = 1; i < sample.Thickness.Length; i++)
                        {
                            if (sample.SW[i] < CLLVolMapped[i])
                            {
                                sample.SW[i] = CLLVolMapped[i];
                            }
                        }
                    }
                }
            }
        }
Beispiel #12
0
 private Document()
 {
     SetRelayCommands();
     UndoManager            = new UndoManager();
     LayerStructure         = new LayerStructure(this);
     XamlAccesibleViewModel = ViewModelMain.Current;
     GeneratePreviewLayer();
     Layers.CollectionChanged += Layers_CollectionChanged;
     LayerStructure.Groups.CollectionChanged += Groups_CollectionChanged;
     LayerStructure.LayerStructureChanged    += LayerStructure_LayerStructureChanged;
     DocumentSizeChanged += (sender, args) =>
     {
         ActiveSelection = new Selection(Array.Empty <Coordinates>(), new PixelSize(args.NewWidth, args.NewHeight));
         Renderer.Resize(args.NewWidth, args.NewHeight);
         GeneratePreviewLayer();
     };
 }
Beispiel #13
0
        /// <summary>
        /// Gets final layer opacity taking into consideration parent groups.
        /// </summary>
        /// <param name="layer">Layer to check.</param>
        /// <returns>Float from range 0-1.</returns>
        public static float GetFinalLayerOpacity(Layer layer, LayerStructure structure)
        {
            if (layer.Opacity == 0)
            {
                return(0f);
            }

            var group = structure.GetGroupByLayer(layer.LayerGuid);
            GuidStructureItem groupToCheck = group;
            float             finalOpacity = layer.Opacity;

            while (groupToCheck != null)
            {
                finalOpacity *= groupToCheck.Opacity;
                groupToCheck  = groupToCheck.Parent;
            }

            return(Math.Clamp(finalOpacity, 0f, 1f));
        }
        private bool TryFindStructureDifferences(LayerStructure structure)
        {
            bool structureModified = false;

            if (lastStructure.Count != structure.Groups.Count)
            {
                return(true);
            }


            foreach (GuidStructureItem treeItem in lastStructure)
            {
                var matchingGroup = structure.Groups.FirstOrDefault(x => x.GroupGuid == treeItem.GroupGuid);
                List <GuidStructureItem> changedGroups = new List <GuidStructureItem>();
                if (matchingGroup == null || StructureMismatch(treeItem, matchingGroup))
                {
                    structureModified = true;
                }
            }

            return(structureModified);
        }
Beispiel #15
0
        public void PerceptronWeightsAreFilled()
        {
            LayerStructure structure  = new LayerStructure(5, new[] { 9, 9 }, 7);
            Perceptron     perceptron = new Perceptron(GetInitParamsByLayerStructure(structure));

            perceptron.FillWeightsRandomly();

            bool isFilled = true;

            for (int i = 0; i < 5; i++)
            {
                float randomWeight = GetRandomWeight(perceptron.Weights);

                if (randomWeight < 0 || randomWeight > 1)
                {
                    isFilled = false;
                    break;
                }
            }

            Assert.IsTrue(isFilled);
        }
        /// <summary>
        /// Gets final layer IsVisible taking into consideration group visibility.
        /// </summary>
        /// <param name="layer">Layer to check.</param>
        /// <returns>True if is visible, false if at least parent is not visible or layer itself is invisible.</returns>
        public static bool GetFinalLayerIsVisible(Layer layer, LayerStructure structure)
        {
            if (!layer.IsVisible)
            {
                return(false);
            }

            var  group = structure.GetGroupByLayer(layer.GuidValue);
            bool atLeastOneParentIsInvisible = false;
            GuidStructureItem groupToCheck   = group;

            while (groupToCheck != null)
            {
                if (!groupToCheck.IsVisible)
                {
                    atLeastOneParentIsInvisible = true;
                    break;
                }

                groupToCheck = groupToCheck.Parent;
            }

            return(!atLeastOneParentIsInvisible);
        }
Beispiel #17
0
        public static Surface CombineLayers(Int32Rect portion, IEnumerable <Layer> layers, LayerStructure structure = null)
        {
            Surface finalSurface = new(portion.Width, portion.Height);

            using SKPaint paint = new();

            for (int i = 0; i < layers.Count(); i++)
            {
                Layer layer = layers.ElementAt(i);
                if (structure != null && !LayerStructureUtils.GetFinalLayerIsVisible(layer, structure))
                {
                    continue;
                }
                float layerOpacity = structure == null ? layer.Opacity : LayerStructureUtils.GetFinalLayerOpacity(layer, structure);
                paint.Color = new(255, 255, 255, (byte)(layerOpacity * 255));

                if (layer.OffsetX < 0 || layer.OffsetY < 0 ||
                    layer.Width + layer.OffsetX > layer.MaxWidth ||
                    layer.Height + layer.OffsetY > layer.MaxHeight)
                {
                    throw new InvalidOperationException("Layers must not extend beyond canvas borders");
                }

                using SKImage snapshot = layer.LayerBitmap.SkiaSurface.Snapshot();
                int x = portion.X - layer.OffsetX;
                int y = portion.Y - layer.OffsetY;
                finalSurface.SkiaSurface.Canvas.DrawImage(
                    snapshot,
                    new SKRect(x, y, portion.Width + x, portion.Height + y),
                    new SKRect(0, 0, portion.Width, portion.Height),
                    paint);
            }

            return(finalSurface);
        }
        /// <summary>
        /// 環境依存コード
        /// </summary>
        private void GenerateDependentCode(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists)
        {
            // ヘッダファイル
            StringBuilder stringBuilderForHeader = new StringBuilder();

            stringBuilderForHeader.AppendLine(@"#ifndef __RTCOP_GENERATED_DEPENDENTCODE__");
            stringBuilderForHeader.AppendLine(@"#define __RTCOP_GENERATED_DEPENDENTCODE__");
            stringBuilderForHeader.AppendLine();
            int classCount = 0;

            foreach (var baseClassName in baseClassNameList)
            {
                var    nss     = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None);
                string nscheck = "";
                for (int i = 0; i < (nss.Length - 1); ++i)
                {
                    if (nscheck == "")
                    {
                        nscheck = nss[i];
                    }
                    else
                    {
                        nscheck += ("::" + nss[i]);
                    }
                    if (baseClassNameList.Contains(nscheck))
                    {
                        stringBuilderForHeader.Append(@"class ");
                    }
                    else
                    {
                        stringBuilderForHeader.Append(@"namespace ");
                    }
                    stringBuilderForHeader.Append(nss[i]);
                    stringBuilderForHeader.Append(@" { ");
                }
                stringBuilderForHeader.Append(@"class ");
                stringBuilderForHeader.Append(nss[nss.Length - 1]);
                stringBuilderForHeader.Append(@";");
                for (int i = 0; i < (nss.Length - 1); ++i)
                {
                    stringBuilderForHeader.Append(@" } ");
                }
                stringBuilderForHeader.AppendLine();
                foreach (var layerStructure in layerStructures)
                {
                    if (layerStructure._FindedPartialClasses[classCount] != null)
                    {
                        stringBuilderForHeader.Append(@"namespace ");
                        stringBuilderForHeader.Append(layerStructure.LayerName);
                        stringBuilderForHeader.Append(@" { ");
                        string cname = baseClassName;
                        if (baseClassName.StartsWith("baselayer::"))
                        {
                            cname = baseClassName.Substring("baselayer::".Length);
                        }
                        var nss2 = cname.Split(new string[] { "::" }, StringSplitOptions.None);
                        nscheck = "";
                        string nscheck2 = "baselayer";
                        for (int i = 0; i < (nss2.Length - 1); ++i)
                        {
                            if (nscheck == "")
                            {
                                nscheck = nss2[i];
                            }
                            else
                            {
                                nscheck += ("::" + nss2[i]);
                            }
                            nscheck2 += ("::" + nss2[i]);
                            if (baseClassNameList.Contains(nscheck) || baseClassNameList.Contains(nscheck2))
                            {
                                stringBuilderForHeader.Append(@"class ");
                            }
                            else
                            {
                                stringBuilderForHeader.Append(@"namespace ");
                            }
                            stringBuilderForHeader.Append(nss2[i]);
                            stringBuilderForHeader.Append(@" { ");
                        }
                        stringBuilderForHeader.Append(@"class ");
                        stringBuilderForHeader.Append(nss2[nss2.Length - 1]);
                        stringBuilderForHeader.Append(@";");
                        for (int i = 0; i < nss2.Length; ++i)
                        {
                            stringBuilderForHeader.Append(@" } ");
                        }
                        stringBuilderForHeader.AppendLine();
                    }
                }
                ++classCount;
            }
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"namespace RTCOP {");
            stringBuilderForHeader.AppendLine(@"namespace Generated {");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"class BaseLayer;");
            foreach (var layerStructure in layerStructures)
            {
                stringBuilderForHeader.Append(@"class ");
                stringBuilderForHeader.Append(layerStructure.LayerName);
                stringBuilderForHeader.AppendLine(@";");
            }
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"namespace DependentCode {");
            stringBuilderForHeader.AppendLine();
            foreach (var layerStructure in layerStructures)
            {
                classCount = 0;
                foreach (var baseClassName in baseClassNameList)
                {
                    if (layerStructure._FindedPartialClasses[classCount] != null)
                    {
                        string cname = baseClassName;
                        if (baseClassName.StartsWith("baselayer::"))
                        {
                            cname = baseClassName.Substring("baselayer::".Length);
                        }
                        stringBuilderForHeader.Append(@"volatile void* GetLayerdObjectFinalizer(::");
                        stringBuilderForHeader.Append(layerStructure.LayerName);
                        stringBuilderForHeader.Append(@"::");
                        stringBuilderForHeader.Append(cname);
                        stringBuilderForHeader.AppendLine(@"* obj);");
                    }
                    ++classCount;
                }
            }
            stringBuilderForHeader.AppendLine();
            classCount = 0;
            foreach (var baseClassName in baseClassNameList)
            {
                var nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None);
                for (int i = 0; i < nss.Length; ++i)
                {
                    stringBuilderForHeader.Append(@"namespace ");
                    stringBuilderForHeader.Append(nss[i]);
                    stringBuilderForHeader.Append(@" { ");
                }
                stringBuilderForHeader.AppendLine();
                stringBuilderForHeader.AppendLine(@"volatile void** GetVirtualFunctionTable(BaseLayer* layer);");
                foreach (var layer in layerStructures)
                {
                    if (layer._FindedPartialClasses[classCount] != null)
                    {
                        stringBuilderForHeader.Append(@"volatile void** GetVirtualFunctionTable(");
                        stringBuilderForHeader.Append(layer.LayerName);
                        stringBuilderForHeader.AppendLine(@"* layer);");
                    }
                }
                stringBuilderForHeader.AppendLine();
                var baseMethodList = baseMethodLists[classCount];
                foreach (var baseMethod in baseMethodList)
                {
                    if (baseMethod != null)
                    {
                        stringBuilderForHeader.Append(baseMethod.ReturnType);
                        stringBuilderForHeader.Append(@" ExecuteProceed_");
                        stringBuilderForHeader.Append(baseMethod.Name);
                        stringBuilderForHeader.Append(@"(void* layerdObject, volatile void* proceed");
                        foreach (var param in baseMethod.Parameters)
                        {
                            stringBuilderForHeader.Append(@", ");
                            stringBuilderForHeader.Append(param);
                        }
                        stringBuilderForHeader.AppendLine(@");");
                    }
                }
                stringBuilderForHeader.AppendLine();
                for (int i = 0; i < nss.Length; ++i)
                {
                    stringBuilderForHeader.Append(@"}");
                }
                stringBuilderForHeader.AppendLine();
                stringBuilderForHeader.AppendLine();
                ++classCount;
            }
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"} // namespace DependentCode {}");
            stringBuilderForHeader.AppendLine(@"} // namespace Generated {}");
            stringBuilderForHeader.AppendLine(@"} // namespace RTCOP {}");
            stringBuilderForHeader.AppendLine(@"#endif // !__RTCOP_GENERATED_DEPENDENTCODE__");
            result.CodeDictionary[@"DependentCode.h"] = stringBuilderForHeader.ToString();

            // ソースコード
            if (Target == DevelopmentTarget.WindowsX64)
            {
                if (Environment == DevelopmentEnvironment.VisualStudio)
                {
                    GenerateDependentCodeForWindowsX64VisualStudio(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    GenerateDependentCodeForWindowsX64MinGW(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
            }
            else if (Target == DevelopmentTarget.WindowsX86)
            {
                if (Environment == DevelopmentEnvironment.VisualStudio)
                {
                    GenerateDependentCodeForWindowsX86VisualStudio(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    GenerateDependentCodeForWindowsX86MinGW(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
            }
            else if (Target == DevelopmentTarget.LinuxX64)
            {
                if (Environment == DevelopmentEnvironment.GCC)
                {
                    GenerateDependentCodeForLinuxX64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    throw new Exception("ターゲットと開発環境の組み合わせが不正です");
                }
            }
            else if (Target == DevelopmentTarget.LinuxX86)
            {
                if (Environment == DevelopmentEnvironment.GCC)
                {
                    GenerateDependentCodeForLinuxX86(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    throw new Exception("ターゲットと開発環境の組み合わせが不正です");
                }
            }
            else if (Target == DevelopmentTarget.LinuxARM)
            {
                if (Environment == DevelopmentEnvironment.GCC)
                {
                    GenerateDependentCodeForLinuxARM(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    throw new Exception("ターゲットと開発環境の組み合わせが不正です");
                }
            }
            else if (Target == DevelopmentTarget.LinuxARM64)
            {
                if (Environment == DevelopmentEnvironment.GCC)
                {
                    GenerateDependentCodeForLinuxARM64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    throw new Exception("ターゲットと開発環境の組み合わせが不正です");
                }
            }
            else if (Target == DevelopmentTarget.macOSX64)
            {
                if (Environment == DevelopmentEnvironment.GCC || Environment == DevelopmentEnvironment.Clang)
                {
                    GenerateDependentCodeForMacOSX64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists);
                }
                else
                {
                    throw new Exception("ターゲットと開発環境の組み合わせが不正です");
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// ベースレイヤ
        /// </summary>
        private void GenerateBaseLayer(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists, List <int> superClassIDs, string includeFilePath)
        {
            // 共通処理
            var headerIncludeFiles = from item in baseLayerStructure.HeaderFileItems
                                     where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include)
                                     select(PreprocessDirective) item;
            var headerImportFiles = from item in baseLayerStructure.HeaderFileItems
                                    where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.ImportLayerHeader)
                                    select(PreprocessDirective) item;
            var srcIncludeFiles = from item in baseLayerStructure.SourceFileItems
                                  where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include)
                                  select(PreprocessDirective) item;
            var srcImportFiles = from item in baseLayerStructure.SourceFileItems
                                 where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.ImportLayerHeader)
                                 select(PreprocessDirective) item;
            // ヘッダファイル
            StringBuilder stringBuilderForHeader = new StringBuilder();

            stringBuilderForHeader.AppendLine(@"#ifndef __RTCOP_GENERATED_BASELAYER__");
            stringBuilderForHeader.AppendLine(@"#define __RTCOP_GENERATED_BASELAYER__");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"#include ""RTCOP/Core/Layer.h""");
            stringBuilderForHeader.AppendLine(@"#include ""RTCOP/Core/LayerdObject.h""");
            stringBuilderForHeader.AppendLine();
            var headerIncludeFilesArray = headerIncludeFiles.ToArray();

            foreach (var incFile in headerIncludeFilesArray)
            {
                stringBuilderForHeader.AppendLine(incFile.ToString());
                baseLayerStructure.HeaderFileItems.Remove(incFile);
            }
            stringBuilderForHeader.AppendLine();
            var           headerImportFilesArray = headerImportFiles.ToArray();
            List <string> layerNamesH            = new List <string>();

            foreach (var impFile in headerImportFilesArray)
            {
                string filePath = "";
                foreach (var incpath in IncludePaths)
                {
                    string path     = incpath + impFile.Param1;
                    string fullPath = Path.GetFullPath(path);
                    if (File.Exists(fullPath))
                    {
                        filePath = fullPath;
                        break;
                    }
                }
                foreach (var ls in layerStructures)
                {
                    if (ls.LayerName == "baselayer" || layerNamesH.Contains(ls.LayerName))
                    {
                        continue;
                    }
                    if (ls.ImportedLhInfomation.Exists((obj) => obj.FilePath == filePath))
                    {
                        layerNamesH.Add(ls.LayerName);
                    }
                }
                baseLayerStructure.HeaderFileItems.Remove(impFile);
            }
            stringBuilderForHeader.AppendLine(@"#ifdef __RTCOP_GENERAED_CODE_FLAG__");
            foreach (string lname in layerNamesH)
            {
                stringBuilderForHeader.Append(@"#include """);
                stringBuilderForHeader.Append(lname);
                stringBuilderForHeader.AppendLine(@".h""");
            }
            stringBuilderForHeader.AppendLine(@"#else");
            foreach (string lname in layerNamesH)
            {
                stringBuilderForHeader.Append(@"#include """);
                stringBuilderForHeader.Append(includeFilePath);
                stringBuilderForHeader.Append(lname);
                stringBuilderForHeader.AppendLine(@".h""");
            }
            stringBuilderForHeader.AppendLine(@"#endif");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"namespace RTCOP {");
            stringBuilderForHeader.AppendLine(@"namespace Generated {");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"class BaseLayer : public Core::Layer");
            stringBuilderForHeader.AppendLine(@"{");
            stringBuilderForHeader.AppendLine(@"public:");
            stringBuilderForHeader.Append("\t");
            stringBuilderForHeader.AppendLine(@"static BaseLayer* GetInstance();");
            stringBuilderForHeader.Append("\t");
            stringBuilderForHeader.AppendLine(@"explicit BaseLayer(const int id, const char* const name, int numOfBaseClasses, int* numOfBaseMethods);");
            stringBuilderForHeader.Append("\t");
            stringBuilderForHeader.AppendLine(@"virtual ~BaseLayer() override;");
            stringBuilderForHeader.AppendLine(@"protected:");
            stringBuilderForHeader.Append("\t");
            stringBuilderForHeader.AppendLine(@"virtual void* InitializeLayerdObject(void* obj, int classID) override;");
            stringBuilderForHeader.AppendLine(@"};");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"} // namespace Generated {}");
            stringBuilderForHeader.AppendLine(@"} // namespace RTCOP {}");
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(ItemsToStringForBaseLayer(baseLayerStructure.HeaderFileItems, baseClassNameList, baseMethodLists, superClassIDs, 0, ""));
            stringBuilderForHeader.AppendLine();
            stringBuilderForHeader.AppendLine(@"#endif //!__RTCOP_GENERATED_JAPANESELAYER__");
            result.CodeDictionary[@"BaseLayer.h"] = stringBuilderForHeader.ToString();

            // ソースファイル
            StringBuilder stringBuilderForSource = new StringBuilder();

            stringBuilderForSource.AppendLine(@"#include ""COPNewForApp.h""");
            stringBuilderForSource.AppendLine(@"#include ""ActivationForApp.h""");
            stringBuilderForSource.AppendLine(@"#include ""Layer_Private.h""");
            stringBuilderForSource.AppendLine(@"#include ""LayerdObject_Private.h""");
            stringBuilderForSource.AppendLine(@"#include ""DependentCode.h""");
            stringBuilderForSource.AppendLine(@"#include ""RTCOP/Framework.h""");
            stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/RTCOPManager.h""");
            stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/PartialClassMembers.h""");
            stringBuilderForSource.AppendLine(@"#include <cstring>");
            stringBuilderForSource.AppendLine();
            var srcIncludeFilesArray = srcIncludeFiles.ToArray();

            foreach (var incFile in srcIncludeFilesArray)
            {
                stringBuilderForSource.AppendLine(incFile.ToString());
                baseLayerStructure.SourceFileItems.Remove(incFile);
            }
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"#define __RTCOP_GENERAED_CODE_FLAG__");
            stringBuilderForSource.AppendLine(@"#include ""BaseLayer.h""");
            var           srcImportFilesArray = srcImportFiles.ToArray();
            List <string> layerNamesS         = new List <string>();

            foreach (var impFile in srcImportFilesArray)
            {
                string filePath = "";
                foreach (var incpath in IncludePaths)
                {
                    string path     = incpath + impFile.Param1;
                    string fullPath = Path.GetFullPath(path);
                    if (File.Exists(fullPath))
                    {
                        filePath = fullPath;
                        break;
                    }
                }
                foreach (var ls in layerStructures)
                {
                    if (layerNamesS.Contains(ls.LayerName))
                    {
                        continue;
                    }
                    if (ls.ImportedLhInfomation.Exists((obj) => obj.FilePath == filePath))
                    {
                        stringBuilderForSource.Append(@"#include """);
                        stringBuilderForSource.Append(ls.LayerName);
                        stringBuilderForSource.AppendLine(@".h""");
                        layerNamesS.Add(ls.LayerName);
                    }
                }
                baseLayerStructure.SourceFileItems.Remove(impFile);
            }
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"namespace RTCOP {");
            stringBuilderForSource.AppendLine(@"namespace Generated {");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"BaseLayer* BaseLayer::GetInstance()");
            stringBuilderForSource.AppendLine(@"{");
            stringBuilderForSource.Append("\t");
            stringBuilderForSource.AppendLine(@"return (BaseLayer*)RTCOP::Framework::Instance->GetRTCOPManager()->GetLayer((int)LayerID::baselayer);");
            stringBuilderForSource.AppendLine(@"}");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"BaseLayer::BaseLayer(const int id, const char* const name, int numOfBaseClasses, int* numOfBaseMethods)");
            stringBuilderForSource.Append("\t");
            stringBuilderForSource.AppendLine(@":Core::Layer(id, name, numOfBaseClasses, numOfBaseMethods)");
            stringBuilderForSource.AppendLine(@"{");
            int classcount = 0;

            foreach (string classname in baseClassNameList)
            {
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.Append(@"int size");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.Append(@" = sizeof(volatile void*) * numOfBaseMethods[");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.AppendLine(@"];");
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.Append(@"volatile void** virtualFunctionTable");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.Append(@" = DependentCode::");
                stringBuilderForSource.Append(classname);
                stringBuilderForSource.AppendLine(@"::GetVirtualFunctionTable(this);");
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.Append(@"std::memcpy(_Private->_VirtualFunctionTables[");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.Append(@"], virtualFunctionTable");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.Append(@", size");
                stringBuilderForSource.Append(classcount);
                stringBuilderForSource.AppendLine(@");");
                ++classcount;
            }
            stringBuilderForSource.AppendLine(@"}");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"BaseLayer::~BaseLayer()");
            stringBuilderForSource.AppendLine(@"{");
            stringBuilderForSource.AppendLine(@"}");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"void* BaseLayer::InitializeLayerdObject(void* obj, int classID)");
            stringBuilderForSource.AppendLine(@"{");
            stringBuilderForSource.Append("\t");
            stringBuilderForSource.AppendLine(@"return obj;");
            stringBuilderForSource.AppendLine(@"}");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"} // namespace Generated {}");
            stringBuilderForSource.AppendLine(@"} // namespace RTCOP {}");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(ItemsToStringForBaseLayer(baseLayerStructure.SourceFileItems, baseClassNameList, baseMethodLists, superClassIDs, 0, ""));
            stringBuilderForSource.AppendLine();
            result.CodeDictionary[@"BaseLayer.cpp"] = stringBuilderForSource.ToString();
        }
Beispiel #20
0
        /// <summary>
        /// コード生成
        /// </summary>
        /// <param name="mergedLSFile">マージ済みのレイヤ構造ファイル</param>
        /// <param name="includeFilePath">インクルードファイルパス</param>
        /// <returns>生成後のソースコード</returns>
        public GeneratedCodes GenerateCode(LayerStructureFile mergedLSFile, string includeFilePath)
        {
            GeneratedCodes result = new GeneratedCodes();

            // ライブラリのヘッダファイルを追加
            result.CodeDictionary[@"Layer_Private.h"]        = Properties.Resources.Layer_Private_Header;
            result.CodeDictionary[@"LayerdObject_Private.h"] = Properties.Resources.LayerdObject_Private_Header;
            // ベースクラスを調べる
            LayerStructure baselayerStructure = mergedLSFile.BaseLayerStructure;

            if (baselayerStructure == null)
            {
                // ベースレイヤは定義されていなくても、自動的に生成される
                baselayerStructure = new LayerStructure("baselayer");
                mergedLSFile.BaseLayerStructure = baselayerStructure;
            }
            List <string> baseClassNameList = new List <string>();
            List <List <LayerdMethodDefinition> > baseMethodLists  = new List <List <LayerdMethodDefinition> >();
            List <List <ConstructorDefinition> >  constructorLists = new List <List <ConstructorDefinition> >();
            List <int> superClassIDs = new List <int>();
            Action <IEnumerable <object>, string, int> createBaseClassAndMethodList = null;

            createBaseClassAndMethodList = (items, nspace, classId) =>
            {
                foreach (object item in items)
                {
                    if (item is LayerDefinition)
                    {
                        var    ld      = (LayerDefinition)item;
                        string nspace2 = "baselayer";
                        createBaseClassAndMethodList(ld.Contents, nspace2, -1);
                    }
                    else if (item is NamespaceDefinition)
                    {
                        var    nd      = (NamespaceDefinition)item;
                        string nspace2 = nd.Name;
                        if (nspace != "")
                        {
                            nspace2 = nspace + "::" + nspace2;
                        }
                        createBaseClassAndMethodList(nd.Contents, nspace2, -1);
                    }
                    else if (item is LayerdClassDefinition)
                    {
                        var    lcd       = (LayerdClassDefinition)item;
                        string classname = lcd.Name;
                        if (nspace != "")
                        {
                            classname = nspace + "::" + classname;
                        }
                        if (!baseClassNameList.Contains(classname))
                        {
                            baseClassNameList.Add(classname);
                            baseMethodLists.Add(new List <LayerdMethodDefinition>());
                            constructorLists.Add(new List <ConstructorDefinition>());
                            int id = baseClassNameList.IndexOf(classname);
                            if (lcd.SuperClasses.Count >= 1)
                            {
                                string superclassFullname = lcd.SuperClasses[0].ClassName;
                                if (nspace != "")
                                {
                                    superclassFullname = nspace + "::" + superclassFullname;
                                }
                                string[] superclassNspaces = superclassFullname.Split(new string[] { "::" }, StringSplitOptions.None);
                                string   sname             = superclassFullname;
                                int      superId           = -1;
                                for (int i = 0; i < superclassNspaces.Length; ++i)
                                {
                                    int id2 = baseClassNameList.IndexOf(sname);
                                    if (id2 != -1)
                                    {
                                        baseMethodLists[id].AddRange(baseMethodLists[id2]);
                                        superId = id2;
                                        break;
                                    }
                                    sname = sname.Remove(0, (superclassNspaces[i].Length + 2));
                                }
                                superClassIDs.Add(superId);
                            }
                            else
                            {
                                superClassIDs.Add(-1);
                            }
                            createBaseClassAndMethodList(lcd.Contents, classname, id);
                            // デストラクタ無ければ追加
                            var baseMethodList = baseMethodLists[id];
                            if (!baseMethodList.Exists((obj) => obj == null))
                            {
                                baseMethodList.Add(null);
                            }
                        }
                        else
                        {
                            throw new Exception("クラス" + classname + "の定義が重複しています");
                        }
                    }
                    else if (item is ConstructorDefinition)
                    {
                        var cd   = (ConstructorDefinition)item;
                        var list = constructorLists[classId];
                        list.Add(cd);
                    }
                    else if (item is DestructorDefinition)
                    {
                        var dd = (DestructorDefinition)item;
                        if (dd.IsVirtual || dd.IsPureVirtual)
                        {
                            var methodList = baseMethodLists[classId];
                            if (!methodList.Exists((obj) => obj == null))
                            {
                                methodList.Add(null);
                            }
                        }
                    }
                    else if (item is LayerdMethodDefinition)
                    {
                        if (classId == -1)
                        {
                            continue;
                        }
                        var lmd = (LayerdMethodDefinition)item;
                        if (((lmd.IsBase != null) && lmd.IsBase.Value) || lmd.IsVirtual || lmd.IsPureVirtual)
                        {
                            var methodList = baseMethodLists[classId];
                            if (!methodList.Exists((obj) => (obj != null) && (obj.CompareMethod(lmd))))
                            {
                                methodList.Add(lmd);
                            }
                        }
                    }
                }
            };
            createBaseClassAndMethodList(baselayerStructure.HeaderFileItems, "", -1);
            createBaseClassAndMethodList(baselayerStructure.SourceFileItems, "", -1);
            createBaseClassAndMethodList(mergedLSFile.BaseClassHeaderItems, "", -1);
            // レイヤ、クラス、メソッドの数を調べる
            int numOfLayers  = mergedLSFile.LayerStructures.Count + 1;
            int numOfClasses = baseClassNameList.Count;

            int[] numOfMethods = new int[numOfClasses];
            for (int i = 0; i < numOfClasses; ++i)
            {
                numOfMethods[i] = baseMethodLists[i].Count;
            }

            //=======================================
            // ↓これらは別ファイルで定義
            //=======================================
            // RTCOPAppInitializerの生成
            GenerateRTCOPAppInitializer(result, numOfLayers, numOfClasses, numOfMethods, mergedLSFile.LayerStructures, includeFilePath);
            // API.h、COPNewForApp.h、ActivationForApp.hの生成
            GenerateAPIHeaders(result, mergedLSFile.LayerStructures, baseClassNameList, includeFilePath);
            // ベースレイヤの生成
            GenerateBaseLayer(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, superClassIDs, includeFilePath);
            // 各レイヤの生成
            GenerateLayers(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, constructorLists, superClassIDs, includeFilePath);
            // 環境依存コードの生成
            GenerateDependentCode(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, includeFilePath);

            // 結果を返す
            return(result);
        }
Beispiel #21
0
        /// <summary>
        /// コンパイル
        /// </summary>
        /// <param name="sourceFile">ソースファイル</param>
        /// <returns>レイヤ構造ファイル</returns>
        public LayerStructureFile Compile(RTCOPSourceFile sourceFile)
        {
            // 結果を格納するためのレイヤ構造ファイル
            LayerStructureFile result = new LayerStructureFile();
            // パーサに通す
            string sourceCode = sourceFile.Text;
            var    items      = RTCOPParser.RTCOPSourceFile.Parse(sourceCode);
            // 各レイヤ共通のアイテム
            List <object> commonItemsS = new List <object>();
            List <object> commonItemsH = new List <object>();

            // 要素の解釈
            foreach (object item in items)
            {
                // レイヤ定義の場合
                if (item is LayerDefinition)
                {
                    var layerDefinition = (LayerDefinition)item;
                    if (layerDefinition.Name == "baselayer")
                    {
                        if (result.BaseLayerStructure == null)
                        {
                            result.BaseLayerStructure = new LayerStructure("baselayer");
                        }
                        result.BaseLayerStructure.SourceFileItems.Add(layerDefinition);
                    }
                    else
                    {
                        var layerStructure = result.LayerStructures.Find((obj) => obj.LayerName == layerDefinition.Name);
                        if (layerStructure == null)
                        {
                            layerStructure = new LayerStructure(layerDefinition.Name);
                            result.LayerStructures.Add(layerStructure);
                        }
                        layerStructure.SourceFileItems.Add(layerDefinition);
                    }
                }
                // それ以外
                else
                {
                    commonItemsS.Add(item);
                }
            }
            // 各レイヤ共通のアイテムの反映
            if (result.BaseLayerStructure != null)
            {
                result.BaseLayerStructure.SourceFileItems.InsertRange(0, commonItemsS);
            }
            foreach (var layerStructure in result.LayerStructures)
            {
                layerStructure.SourceFileItems.InsertRange(0, commonItemsS);
            }

            // ヘッダファイルの解釈
            Action <RTCOPSourceFile> InterpretImportedFiles = null;

            InterpretImportedFiles = (src) =>
            {
                foreach (RTCOPSourceFile impFile in src.ImportedFiles)
                {
                    // .lh内でさらに読み込まれているファイルをチェック
                    InterpretImportedFiles(impFile);

                    // パーサに通す
                    string impFileCode  = impFile.Text;
                    var    impFileItems = RTCOPParser.RTCOPSourceFile.Parse(impFileCode);
                    // ファイルの種類によって処理方法を変える
                    if (Path.GetExtension(impFile.FilePath) == ".lh")
                    {
                        List <string> layerNames = new List <string>();
                        // 要素の解釈
                        foreach (object item in impFileItems)
                        {
                            // レイヤ定義の場合
                            if (item is LayerDefinition)
                            {
                                var layerDefinition = (LayerDefinition)item;
                                layerNames.Add(layerDefinition.Name);
                                // ヘッダ要素の追加
                                if (layerDefinition.Name == "baselayer")
                                {
                                    // ベースレイヤ
                                    if (result.BaseLayerStructure == null)
                                    {
                                        result.BaseLayerStructure = new LayerStructure("baselayer");
                                    }
                                    ImportedFileInfomation ifi = result.BaseLayerStructure.ImportedLhInfomation.Find((obj) => obj.FilePath == impFile.FilePath);
                                    if (ifi == null)
                                    {
                                        ifi            = new ImportedFileInfomation(impFile.FilePath);
                                        ifi.StartIndex = result.BaseLayerStructure.HeaderFileItems.Count;
                                        ifi.NumOfItems = 0;
                                        result.BaseLayerStructure.ImportedLhInfomation.Add(ifi);
                                    }
                                    ++ifi.NumOfItems;
                                    result.BaseLayerStructure.HeaderFileItems.Add(layerDefinition);
                                }
                                else
                                {
                                    // ベースレイヤ以外
                                    var layerStructure = result.LayerStructures.Find((obj) => obj.LayerName == layerDefinition.Name);
                                    if (layerStructure == null)
                                    {
                                        layerStructure = new LayerStructure(layerDefinition.Name);
                                        result.LayerStructures.Add(layerStructure);
                                    }
                                    ImportedFileInfomation ifi = layerStructure.ImportedLhInfomation.Find((obj) => obj.FilePath == impFile.FilePath);
                                    if (ifi == null)
                                    {
                                        ifi            = new ImportedFileInfomation(impFile.FilePath);
                                        ifi.StartIndex = layerStructure.HeaderFileItems.Count;
                                        ifi.NumOfItems = 0;
                                        layerStructure.ImportedLhInfomation.Add(ifi);
                                    }
                                    ++ifi.NumOfItems;
                                    layerStructure.HeaderFileItems.Add(layerDefinition);
                                }
                            }
                            // それ以外
                            else
                            {
                                commonItemsH.Add(item);
                            }
                        }
                        // 各レイヤ共通のアイテムの反映
                        if (layerNames.Contains("baselayer"))
                        {
                            ImportedFileInfomation ifi = result.BaseLayerStructure.ImportedLhInfomation.Find((obj) => obj.FilePath == impFile.FilePath);
                            ifi.NumOfItems += commonItemsH.Count;
                            result.BaseLayerStructure.HeaderFileItems.InsertRange(ifi.StartIndex, commonItemsH);
                        }
                        foreach (var layerStructure in result.LayerStructures)
                        {
                            if (layerNames.Contains(layerStructure.LayerName))
                            {
                                ImportedFileInfomation ifi = layerStructure.ImportedLhInfomation.Find((obj) => obj.FilePath == impFile.FilePath);
                                ifi.NumOfItems += commonItemsH.Count;
                                layerStructure.HeaderFileItems.InsertRange(ifi.StartIndex, commonItemsH);
                            }
                        }
                    }
                    // .lhファイル以外
                    else
                    {
                        ImportedFileInfomation ifi = new ImportedFileInfomation(impFile.FilePath);
                        ifi.StartIndex = result.BaseClassHeaderItems.Count;
                        ifi.NumOfItems = impFileItems.Count();
                        result.ImportedBaseClassHeaderInfomation.Add(ifi);
                        result.BaseClassHeaderItems.AddRange(impFileItems);
                    }
                }
            };
            InterpretImportedFiles(sourceFile);
            // 結果を返す
            return(result);
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            //Set the path of the file containing the data set
            //string dataFilePath = @"C:\Users\kevin\Desktop\squaredtest.csv"; NutrioxDataset
            string dataFilePath = @"C:\Users\Bruker\Desktop\NutrioxDataset.csv";

            //string dataFilePath = @"C:\Users\Bruker\Desktop\-5to5-200Rows.csv";

            //Create a new data set
            DataSet.DataSet dataSet = new DataSet.DataSet(dataFilePath, true);

            //Apply desired data preprocessing to the data set
            dataSet.PreProcessDataSet(NormalizationType.MinMax, 2, EncodingType.None, null);

            //Create a model hyperparameter layer structure
            LayerStructure layerStructure = new LayerStructure()
            {
                numberOfInputNodes = 2, HiddenLayerList = new List <int> {
                    5, 5
                }, numberOfOutputNodes = 1
            };

            //Create an instance of the desired optimalization strategy to use

            var regularizationStrategyFactory = new RegularizationStrategyFactory();
            StochasticGradientDescent SGD     = new StochasticGradientDescent(new SigmoidFunction(), new IdentityFunction(), new MeanSquaredError(), RegularizationType.None, regularizationStrategyFactory);

            //Create training hyperparameters
            TrainingParameters trainingParams = new TrainingParameters()
            {
                epochs = 500, learningRate = 0.01, momentum = 0.01, RegularizationLambda = 0.00
            };

            //Create an instance of a neural network
            //ArtificialNeuralNetwork ann = new ArtificialNeuralNetwork(layerStructure, trainingParams, dataSet, SGD, new GaussianDistribution());

            //Or Load a Network from XML

            XML xml = new XML();

            ArtificialNeuralNetwork ann = xml.LoadNetwork(@"C:\Users\Bruker\Desktop\BestNet.xml", dataSet) as ArtificialNeuralNetwork;

            //Apply the desired training/test data set split ratios.
            ann.SplitDataSetIntoTrainAndTestSets(0.7);

            //Initiate network training
            //ann.TrainNetwork();

            var crossValidationStrategyFactory = new CrossValidationStrategyFactory();
            NetworkEvaluator evaluator         = new NetworkEvaluator(ann);
            CrossValidator   crossValidator    = new CrossValidator(ann, evaluator, crossValidationStrategyFactory);

            //Cross-validate the fitted model
            //crossValidator.KFold(10, 0.007);

            //Evaluate the fitted model on the test set
            evaluator.EvaluateNetwork(0.007);


            //--Optional--//

            //Serialize and save the fitted model

            //XML xml = new XML();
            //xml.SaveNetwork(dataFilePath, ann);

            //Extract model information

            //ann.SaveListOfErrors();

            //ann.GetApproximatedFunction(ann.SavePath + "/Function.txt");

            Console.ReadLine();
        }
Beispiel #23
0
        public INetwork LoadNetwork(string xmlFilePath, IDataSet dataset)
        {
            _xmlDoc = new XmlDocument();

            _filepath = xmlFilePath;

            _xmlDoc.Load(_filepath);


            //Create Training Params---------------------8::::::::::::::>----------------------------------------


            TrainingParameters trainingParams = new TrainingParameters()
            {
                epochs = Convert.ToInt32(GetXmlValue("NeuralNetwork/Settings/TrainingParameters/Epochs")),

                learningRate = Convert.ToDouble(GetXmlValue("NeuralNetwork/Settings/TrainingParameters/LearningRate")),

                momentum = Convert.ToDouble(GetXmlValue("NeuralNetwork/Settings/TrainingParameters/Momentum"))
            };


            //Create LayerStructure---------------------8::::::::::::::>----------------------------------------


            List <int> hiddenLayersList = new List <int>();

            int numberOfHiddenLayers = Convert.ToInt32(GetXmlValue("NeuralNetwork/Settings/LayerStructure/NumberOfHiddenLayers"));

            for (int i = 1; i <= numberOfHiddenLayers; i++)
            {
                int numberOfNeuronsInHiddenLayer = Convert.ToInt32(GetXmlValue("NeuralNetwork/Settings/LayerStructure/NumberOfNeuronsInHiddenLayer" + i.ToString()));

                hiddenLayersList.Add(numberOfNeuronsInHiddenLayer);
            }

            LayerStructure layerStructure = new LayerStructure()
            {
                numberOfInputNodes = Convert.ToInt32(GetXmlValue("NeuralNetwork/Settings/LayerStructure/NumberOfInputNeurons")),

                numberOfOutputNodes = Convert.ToInt32(GetXmlValue("NeuralNetwork/Settings/LayerStructure/NumberOfOutputNeurons")),

                HiddenLayerList = hiddenLayersList
            };


            //Create Distribution Type---------------------8::::::::::::::>----------------------------------------


            string distribution = GetXmlValue("NeuralNetwork/Settings/DistributionType/InitialRandomDistributionType");

            var distributionType = Type.GetType(distribution + ",NeuralNetwork.Core");

            IInitialRandomDistributionType initialDistribution = Activator.CreateInstance(distributionType) as IInitialRandomDistributionType;


            //Create Strategy---------------------8::::::::::::::>----------------------------------------


            string hiddenFunction = GetXmlValue("NeuralNetwork/Settings/Strategy/HiddenLayerActivationFunction");

            string outputFunction = GetXmlValue("NeuralNetwork/Settings/Strategy/OutputLayerActivationFunction");

            string costFunc = GetXmlValue("NeuralNetwork/Settings/Strategy/CostFunction");

            string regularizationEnum = GetXmlValue("NeuralNetwork/Settings/Strategy/RegularizationType");

            string regularizationStrategyFactory = GetXmlValue("NeuralNetwork/Settings/Strategy/RegularizationStrategyFactory");

            var hiddenFunctionType = Type.GetType(hiddenFunction + ",NeuralNetwork.Core");

            var outputFunctionType = Type.GetType(outputFunction + ",NeuralNetwork.Core");

            var costFunctionType = Type.GetType(costFunc + ",NeuralNetwork.Core");

            var regularizationStrategyFactoryType = Type.GetType(regularizationStrategyFactory + ",NeuralNetwork.Core");

            IActivationFunction hiddenActivationFunction = Activator.CreateInstance(hiddenFunctionType) as IActivationFunction;

            IActivationFunction outputActivationFunction = Activator.CreateInstance(outputFunctionType) as IActivationFunction;

            ICostFunction costFunction = Activator.CreateInstance(costFunctionType) as ICostFunction;

            RegularizationType regularizationType = (RegularizationType)Enum.Parse(typeof(RegularizationType), regularizationEnum);

            IRegularizationStrategyFactory regularizationStrategyFact = Activator.CreateInstance(regularizationStrategyFactoryType) as IRegularizationStrategyFactory;

            string optimizationStrategy = GetXmlValue("NeuralNetwork/Settings/Strategy/OptimizationStrategy");

            var optStrategy = Type.GetType(optimizationStrategy + ",NeuralNetwork.Core");

            IOptimizationStrategy strategy = Activator.CreateInstance(optStrategy, hiddenActivationFunction, outputActivationFunction, costFunction, regularizationType, regularizationStrategyFact) as IOptimizationStrategy;


            //Create Network---------------------8::::::::::::::>----------------------------------------


            network = new ArtificialNeuralNetwork(layerStructure, trainingParams, dataset, strategy, initialDistribution);


            //Set Weights---------------------8::::::::::::::>----------------------------------------


            network.Weights.Clear();

            LoadInputWeights();

            LoadHiddenWeights();


            //Set Biases---------------------8::::::::::::::>----------------------------------------


            network.Biases.Clear();

            LoadHiddenBiases();

            LoadOutputBiases();


            //Clear XMLDoc---------------------8::::::::::::::>----------------------------------------


            _xmlDoc = null;

            return(network);
        }
Beispiel #24
0
        /// <summary>
        ///     Converts layers bitmaps into one bitmap.
        /// </summary>
        /// <param name="width">Width of final bitmap.</param>
        /// <param name="height">Height of final bitmap.</param>.
        /// <param name="layers">Layers to combine.</param>
        /// <returns>WriteableBitmap of layered bitmaps.</returns>
        public static WriteableBitmap CombineLayers(int width, int height, IEnumerable <Layer> layers, LayerStructure structure = null)
        {
            WriteableBitmap finalBitmap = BitmapFactory.New(width, height);

            using (finalBitmap.GetBitmapContext())
            {
                for (int i = 0; i < layers.Count(); i++)
                {
                    Layer layer        = layers.ElementAt(i);
                    float layerOpacity = structure == null ? layer.Opacity : LayerStructureUtils.GetFinalLayerOpacity(layer, structure);

                    if (layer.OffsetX < 0 || layer.OffsetY < 0 ||
                        layer.Width + layer.OffsetX > layer.MaxWidth ||
                        layer.Height + layer.OffsetY > layer.MaxHeight)
                    {
                        throw new InvalidOperationException("Layers must not extend beyond canvas borders");
                    }

                    for (int y = 0; y < layer.Height; y++)
                    {
                        for (int x = 0; x < layer.Width; x++)
                        {
                            Color previousColor = finalBitmap.GetPixel(x + layer.OffsetX, y + layer.OffsetY);
                            Color color         = layer.GetPixel(x, y);

                            finalBitmap.SetPixel(x + layer.OffsetX, y + layer.OffsetY, BlendColor(previousColor, color, layerOpacity));
                        }
                    }
                }
            }

            return(finalBitmap);
        }
Beispiel #25
0
        /// <summary>
        /// レイヤ構造ファイルのマージ
        /// </summary>
        /// <param name="structureFiles">マージしたいレイヤ構造ファイル</param>
        /// <returns>マージされたレイヤ構造ファイル</returns>
        public LayerStructureFile MergeObjectFiles(IEnumerable <LayerStructureFile> structureFiles)
        {
            // 結果を格納するためのオブジェクトファイル
            LayerStructureFile result = new LayerStructureFile();

            // マージ
            foreach (var structureFile in structureFiles)
            {
                // ベースクラスヘッダを重複を防いでマージ
                foreach (var ifi in structureFile.ImportedBaseClassHeaderInfomation)
                {
                    var ifi2 = result.ImportedBaseClassHeaderInfomation.Find((obj) => obj.FilePath == ifi.FilePath);
                    if (ifi2 == null)
                    {
                        ifi2            = new ImportedFileInfomation(ifi.FilePath);
                        ifi2.StartIndex = result.BaseClassHeaderItems.Count;
                        ifi2.NumOfItems = ifi.NumOfItems;
                        result.ImportedBaseClassHeaderInfomation.Add(ifi2);
                        var range = structureFile.BaseClassHeaderItems.GetRange(ifi.StartIndex, ifi.NumOfItems);
                        result.BaseClassHeaderItems.AddRange(range);
                    }
                }
                // ベースレイヤ
                if (structureFile.BaseLayerStructure != null)
                {
                    if (result.BaseLayerStructure == null)
                    {
                        result.BaseLayerStructure = new LayerStructure("baselayer");
                    }
                    result.BaseLayerStructure.SourceFileItems.AddRange(structureFile.BaseLayerStructure.SourceFileItems);
                    // ヘッダ重複を防いでマージ
                    foreach (var ifi in structureFile.BaseLayerStructure.ImportedLhInfomation)
                    {
                        var ifi2 = result.BaseLayerStructure.ImportedLhInfomation.Find((obj) => obj.FilePath == ifi.FilePath);
                        if (ifi2 == null)
                        {
                            ifi2            = new ImportedFileInfomation(ifi.FilePath);
                            ifi2.StartIndex = result.BaseLayerStructure.HeaderFileItems.Count;
                            ifi2.NumOfItems = ifi.NumOfItems;
                            result.BaseLayerStructure.ImportedLhInfomation.Add(ifi2);
                            var range = structureFile.BaseLayerStructure.HeaderFileItems.GetRange(ifi.StartIndex, ifi.NumOfItems);
                            result.BaseLayerStructure.HeaderFileItems.AddRange(range);
                        }
                    }
                }
                // ベースレイヤ以外
                foreach (var layerStructure in structureFile.LayerStructures)
                {
                    var rld = result.LayerStructures.Find((obj) => obj.LayerName == layerStructure.LayerName);
                    if (rld == null)
                    {
                        rld = new LayerStructure(layerStructure.LayerName);
                        result.LayerStructures.Add(rld);
                    }
                    rld.SourceFileItems.AddRange(layerStructure.SourceFileItems);
                    // ヘッダ重複を防いでマージ
                    foreach (var ifi in layerStructure.ImportedLhInfomation)
                    {
                        var ifi2 = rld.ImportedLhInfomation.Find((obj) => obj.FilePath == ifi.FilePath);
                        if (ifi2 == null)
                        {
                            ifi2            = new ImportedFileInfomation(ifi.FilePath);
                            ifi2.StartIndex = rld.HeaderFileItems.Count;
                            ifi2.NumOfItems = ifi.NumOfItems;
                            rld.ImportedLhInfomation.Add(ifi2);
                            var range = layerStructure.HeaderFileItems.GetRange(ifi.StartIndex, ifi.NumOfItems);
                            rld.HeaderFileItems.AddRange(range);
                        }
                    }
                }
            }
            // レイヤコンフィグの反映
            //result = ReflectConfigFile(result);
            // 結果を返す
            return(result);
        }
Beispiel #26
0
        /// <summary>
        /// 環境依存コード(macOS)
        /// </summary>
        private void GenerateDependentCodeForMacOSX64(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists)
        {
            // cppファイル
            StringBuilder stringBuilderForSource = new StringBuilder();

            stringBuilderForSource.AppendLine(@"#include ""DependentCode.h""");
            stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/LayerdObject.h""");
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"#include ""BaseLayer.h""");
            foreach (var layerStructure in layerStructures)
            {
                stringBuilderForSource.Append(@"#include """);
                stringBuilderForSource.Append(layerStructure.LayerName);
                stringBuilderForSource.AppendLine(@".h""");
            }
            stringBuilderForSource.AppendLine();
            foreach (LayerStructure layerStructure in layerStructures)
            {
                var headerIncludeFiles = from item in layerStructure.HeaderFileItems
                                         where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include)
                                         select(PreprocessDirective) item;
                var srcIncludeFiles = from item in layerStructure.SourceFileItems
                                      where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include)
                                      select(PreprocessDirective) item;
                foreach (var inc in headerIncludeFiles)
                {
                    stringBuilderForSource.Append(@"#include """);
                    stringBuilderForSource.Append(inc.Param1);
                    stringBuilderForSource.AppendLine(@"""");
                }
                foreach (var inc in srcIncludeFiles)
                {
                    stringBuilderForSource.Append(@"#include """);
                    stringBuilderForSource.Append(inc.Param1);
                    stringBuilderForSource.AppendLine(@"""");
                }
            }
            stringBuilderForSource.AppendLine();
            int classCount = 0;

            foreach (var baseClassName in baseClassNameList)
            {
                stringBuilderForSource.Append(@"asm("".rtcop_vft");
                stringBuilderForSource.Append(classCount);
                stringBuilderForSource.Append(@"0: .quad __ZTVN5RTCOP4Core12LayerdObjectI");
                string   end = "EE";
                string[] nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None);
                if (nss.Length >= 2)
                {
                    stringBuilderForSource.Append(@"N");
                    end = "EEE";
                }
                foreach (string ns in nss)
                {
                    stringBuilderForSource.Append(ns.Length);
                    stringBuilderForSource.Append(ns);
                }
                stringBuilderForSource.Append(end);
                stringBuilderForSource.AppendLine(@"+16"");");
                int layerCount = 1;
                foreach (var layerStructure in layerStructures)
                {
                    if (layerStructure._FindedPartialClasses[classCount] != null)
                    {
                        stringBuilderForSource.Append(@"asm("".rtcop_vft");
                        stringBuilderForSource.Append(classCount);
                        stringBuilderForSource.Append(layerCount);
                        stringBuilderForSource.Append(@": .quad __ZTVN");
                        stringBuilderForSource.Append(layerStructure.LayerName.Length);
                        stringBuilderForSource.Append(layerStructure.LayerName);
                        foreach (string ns in nss)
                        {
                            if (ns != "baselayer")
                            {
                                stringBuilderForSource.Append(ns.Length);
                                stringBuilderForSource.Append(ns);
                            }
                        }
                        stringBuilderForSource.AppendLine(@"E+16"");");
                        stringBuilderForSource.Append(@"asm("".rtcop_vfaddr");
                        stringBuilderForSource.Append(classCount);
                        stringBuilderForSource.Append(layerCount);
                        stringBuilderForSource.Append(@": .quad __ZN");
                        stringBuilderForSource.Append(layerStructure.LayerName.Length);
                        stringBuilderForSource.Append(layerStructure.LayerName);
                        foreach (string ns in nss)
                        {
                            if (ns != "baselayer")
                            {
                                stringBuilderForSource.Append(ns.Length);
                                stringBuilderForSource.Append(ns);
                            }
                        }
                        stringBuilderForSource.AppendLine(@"27_RTCOP_FinalizePartialClassEv"");");
                    }
                    ++layerCount;
                }
                stringBuilderForSource.AppendLine();
                ++classCount;
            }
            stringBuilderForSource.AppendLine();
            stringBuilderForSource.AppendLine(@"namespace RTCOP {");
            stringBuilderForSource.AppendLine(@"namespace Generated {");
            stringBuilderForSource.AppendLine(@"namespace DependentCode {");
            stringBuilderForSource.AppendLine();
            classCount = 0;
            foreach (var baseClassName in baseClassNameList)
            {
                var nss        = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None);
                int layerCount = 1;
                foreach (var layerStructure in layerStructures)
                {
                    if (layerStructure._FindedPartialClasses[classCount] != null)
                    {
                        stringBuilderForSource.Append(@"volatile void* GetLayerdObjectFinalizer(::");
                        stringBuilderForSource.Append(layerStructure.LayerName);
                        stringBuilderForSource.Append(@"::");
                        for (int i = 0; i < (nss.Length - 1); ++i)
                        {
                            string ns = nss[i];
                            if (ns != "baselayer")
                            {
                                stringBuilderForSource.Append(ns);
                                stringBuilderForSource.Append(@"::");
                            }
                        }
                        stringBuilderForSource.Append(nss[nss.Length - 1]);
                        stringBuilderForSource.AppendLine(@"* obj)");
                        stringBuilderForSource.AppendLine(@"{");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.AppendLine(@"volatile void* vfp = 0;");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vfaddr");
                        stringBuilderForSource.Append(classCount);
                        stringBuilderForSource.Append(layerCount);
                        stringBuilderForSource.AppendLine(@"(%%rip), %0"" : ""=r""(vfp) : : ""memory""); ");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.AppendLine(@"return vfp;");
                        stringBuilderForSource.AppendLine(@"}");
                        stringBuilderForSource.AppendLine();
                    }
                    ++layerCount;
                }
                stringBuilderForSource.AppendLine();
                for (int i = 0; i < nss.Length; ++i)
                {
                    stringBuilderForSource.Append(@"namespace ");
                    stringBuilderForSource.Append(nss[i]);
                    stringBuilderForSource.Append(@" { ");
                }
                stringBuilderForSource.AppendLine();
                stringBuilderForSource.AppendLine(@"volatile void** GetVirtualFunctionTable(BaseLayer* layer)");
                stringBuilderForSource.AppendLine(@"{");
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.AppendLine(@"volatile void** vft = 0;");
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vft");
                stringBuilderForSource.Append(classCount);
                stringBuilderForSource.AppendLine(@"0(%%rip), %0"" : ""=r""(vft) : : ""memory""); ");
                stringBuilderForSource.Append("\t");
                stringBuilderForSource.AppendLine(@"return vft;");
                stringBuilderForSource.AppendLine(@"}");
                stringBuilderForSource.AppendLine();
                layerCount = 1;
                foreach (var layerStructure in layerStructures)
                {
                    if (layerStructure._FindedPartialClasses[classCount] != null)
                    {
                        stringBuilderForSource.Append(@"volatile void** GetVirtualFunctionTable(");
                        stringBuilderForSource.Append(layerStructure.LayerName);
                        stringBuilderForSource.AppendLine(@"* layer)");
                        stringBuilderForSource.AppendLine(@"{");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.AppendLine(@"volatile void** vft = 0;");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vft");
                        stringBuilderForSource.Append(classCount);
                        stringBuilderForSource.Append(layerCount);
                        stringBuilderForSource.AppendLine(@"(%%rip), %0"" : ""=r""(vft) : : ""memory""); ");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.AppendLine(@"return vft;");
                        stringBuilderForSource.AppendLine(@"}");
                        stringBuilderForSource.AppendLine();
                    }
                    ++layerCount;
                }
                var baseMethodList = baseMethodLists[classCount];
                foreach (var baseMethod in baseMethodList)
                {
                    if (baseMethod != null)
                    {
                        stringBuilderForSource.Append(baseMethod.ReturnType);
                        stringBuilderForSource.Append(@" ExecuteProceed_");
                        stringBuilderForSource.Append(baseMethod.Name);
                        stringBuilderForSource.Append(@"(void* layerdObject, volatile void* proceed");
                        foreach (var param in baseMethod.Parameters)
                        {
                            stringBuilderForSource.Append(@", ");
                            stringBuilderForSource.Append(param);
                        }
                        stringBuilderForSource.AppendLine(@")");
                        stringBuilderForSource.AppendLine(@"{");
                        stringBuilderForSource.Append("\t");
                        stringBuilderForSource.Append(baseMethod.ReturnType);
                        stringBuilderForSource.Append(@"(*pProceed)(void*");
                        foreach (var param in baseMethod.Parameters)
                        {
                            stringBuilderForSource.Append(@", ");
                            stringBuilderForSource.Append(param.Type);
                        }
                        stringBuilderForSource.Append(@") = (");
                        stringBuilderForSource.Append(baseMethod.ReturnType);
                        stringBuilderForSource.Append(@"(*)(void*");
                        foreach (var param in baseMethod.Parameters)
                        {
                            stringBuilderForSource.Append(@", ");
                            stringBuilderForSource.Append(param.Type);
                        }
                        stringBuilderForSource.AppendLine(@"))proceed;");
                        stringBuilderForSource.Append("\t");
                        if (!((baseMethod.ReturnType.Type.ToString() == "void") && (baseMethod.ReturnType.Pointers.Count == 0)))
                        {
                            stringBuilderForSource.Append(@"return ");
                        }
                        stringBuilderForSource.Append("pProceed(layerdObject");
                        foreach (var param in baseMethod.Parameters)
                        {
                            stringBuilderForSource.Append(@", ");
                            stringBuilderForSource.Append(param.Name);
                        }
                        stringBuilderForSource.AppendLine(");");
                        stringBuilderForSource.AppendLine(@"}");
                    }
                }
                stringBuilderForSource.AppendLine();
                for (int i = 0; i < nss.Length; ++i)
                {
                    stringBuilderForSource.Append(@"}");
                }
                stringBuilderForSource.AppendLine();
                stringBuilderForSource.AppendLine();
                ++classCount;
            }
            stringBuilderForSource.AppendLine(@"} // namespace DependentCode {}");
            stringBuilderForSource.AppendLine(@"} // namespace Generated {}");
            stringBuilderForSource.AppendLine(@"} // namespace RTCOP {}");
            result.CodeDictionary[@"DependentCode.cpp"]    = stringBuilderForSource.ToString();
            result.CodeDictionary[@"DependentCodeAsm.asm"] = "";
        }