Exemplo n.º 1
0
    static int nextInt(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                XRandom obj = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
                int     o   = obj.nextInt();
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 2)
            {
                XRandom obj  = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
                int     arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int     o    = obj.nextInt(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: XRandom.nextInt"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 2
0
    static int _CreateXRandom(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                XRandom obj = new XRandom();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1)
            {
                long    arg0 = LuaDLL.tolua_checkint64(L, 1);
                XRandom obj  = new XRandom(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: XRandom.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 3
0
        private void InitializePiA(TransitionMatrixInput inputParameters, XRandom rng, int matrixSize, int jCorrector)
        {
            var faculty = new Faculty();

            for (var i = 0; i < matrixSize; i++)
            {
                var lineSum = 0.0;
                for (var j = 0; j < matrixSize; j++)
                {
                    if (i != j + jCorrector)
                    {
                        var cellValue =
                            InitializePiACalcCellValue(inputParameters, i, j, matrixSize, faculty, rng, jCorrector);
                        _piA[i, j] = cellValue;
                        lineSum   += cellValue;
                    }
                }

                for (var j = 0; j < matrixSize; j++)
                {
                    _piA[i, j] = _piA[i, j] / lineSum;
                }
            }

            _organizationDegreeA = CalcOrganizationDegree(_piA, matrixSize);
        }
Exemplo n.º 4
0
        private void CreateNetwork()
        {
            if (trainData == null)
            {
                return;
            }

            // create network to hold all input data
            var  inputCount = trainData.InputCount;
            uint numNeurons = Configuration.DefaultHiddenNeurons > 0 ? Configuration.DefaultHiddenNeurons : inputCount / 2 - 1;

            debug($"new network: numinputs: {inputCount} neurons: {numNeurons}");

            Program.Form.AddConfiguration($"\r\nConfig hash: {XRandom.randomString()}\r\n\r\nNetwork:\r\n inputs: {inputCount} neurons: {numNeurons}");

            NetworkType layer = NetworkType.SHORTCUT;

            network = new Network(layer, inputCount, numNeurons, 2)
            {
                TrainingAlgorithm = Configuration.TrainAlgo
            };
            network.newNetwork = true;
            network.InitWeights(trainData);
            network.SetupActivation();
            network.SetupScaling(trainData);
        }
Exemplo n.º 5
0
    protected string RandomTmx(string[] tmxids, XRandom random)
    {
        int           num3;
        List <string> list   = new List <string>();
        int           index  = 0;
        int           length = tmxids.Length;

        while (index < length)
        {
            string str = tmxids[index];
            if (this.CanRandomTmx(str))
            {
                list.Add(str);
            }
            index++;
        }
        if (random != null)
        {
            num3 = random.nextInt(0, list.Count);
        }
        else
        {
            num3 = GameLogic.Random(0, list.Count);
        }
        string tmxid = list[num3];

        this.AddUsedTmx(tmxid);
        if (!GameLogic.Release.MapCreatorCtrl.HaveTmx(tmxid))
        {
            object[] args = new object[] { GameLogic.Hold.BattleData.Level_CurrentStage, tmxid };
            SdkManager.Bugly_Report("RoomGenerateBase", Utils.FormatString("stage:{0} RandomTmx[{1}] is dont have!!!", args));
            return(this.RandomTmx(tmxids));
        }
        return(tmxid);
    }
Exemplo n.º 6
0
        public void NextTest()
        {
            Guid g1 = Guid.NewGuid();
            Guid g2 = Guid.NewGuid();

            XRandom x1  = new XRandom(g1);
            XRandom x11 = new XRandom(g1);
            XRandom x2  = new XRandom(g2);

            Assert.AreEqual(x1.Next(), x11.Next());
            Assert.AreNotEqual(x1.Next(), x2.Next());
        }
Exemplo n.º 7
0
        public void XRandomTest1()
        {
            XRandom x1  = new XRandom(987654321);
            XRandom x11 = new XRandom(987654321);
            XRandom x2  = new XRandom(123456789);

            byte[] b1  = x1.GetBytes(100);
            byte[] b11 = x11.GetBytes(100);
            byte[] b2  = x2.GetBytes(100);

            Assert.IsFalse(b1.HasChanges(b11));
            Assert.IsTrue(b1.HasChanges(b2));
        }
Exemplo n.º 8
0
 static int setSeed(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         XRandom obj  = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
         long    arg0 = LuaDLL.tolua_checkint64(L, 2);
         obj.setSeed(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 9
0
 static int nextGaussian(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         XRandom obj = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
         double  o   = obj.nextGaussian();
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 10
0
 static int nextBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         XRandom obj  = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
         byte[]  arg0 = ToLua.CheckByteBuffer(L, 2);
         obj.nextBytes(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 11
0
 static int nextBoolean(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         XRandom obj = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
         bool    o   = obj.nextBoolean();
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 12
0
 static int nextLong(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         XRandom obj = (XRandom)ToLua.CheckObject <XRandom>(L, 1);
         long    o   = obj.nextLong();
         LuaDLL.tolua_pushint64(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 13
0
        public Form1()
        {
            try
            {
                File.Delete(Configuration.LogFileName);
            }
            catch (Exception e)
            {
                debug($"exception while delete: {e}");
            }

            InitializeComponent();

            XRandom.init();
        }
Exemplo n.º 14
0
        public void XRandomTest()
        {
            Guid g1 = Guid.NewGuid();
            Guid g2 = Guid.NewGuid();

            XRandom x1  = new XRandom(g1);
            XRandom x11 = new XRandom(g1);
            XRandom x2  = new XRandom(g2);

            byte[] b1  = x1.GetBytes(100);
            byte[] b11 = x11.GetBytes(100);
            byte[] b2  = x2.GetBytes(100);

            Assert.IsFalse(b1.HasChanges(b11));
            Assert.IsTrue(b1.HasChanges(b2));
        }
Exemplo n.º 15
0
        public void NextBytesTest()
        {
            XRandom x1  = new XRandom(987654321);
            XRandom x11 = new XRandom(987654321);
            XRandom x2  = new XRandom(123456789);

            byte[] b1  = new byte[100];
            byte[] b11 = new byte[100];
            byte[] b2  = new byte[100];
            x1.NextBytes(b1);
            x11.NextBytes(b11);
            x2.NextBytes(b2);

            Assert.IsFalse(b1.HasChanges(b11));
            Assert.IsTrue(b1.HasChanges(b2));
        }
Exemplo n.º 16
0
        public static string CrownJoe(string str, bool bo)
        {
            char[] chArray = str.ToCharArray();
            string str2    = "";
            string str3    = "";

            for (int i = 0; i < chArray.Length; i++)
            {
                str3 = Convert.ToBase64String(Encoding.UTF8.GetBytes(chArray[i].ToString()));
                if (bo)
                {
                    str3 = str3 + XRandom.Random(10, 0x63).ToString();
                }
                str2 = str2 + str3;
            }
            return(str2);
        }
        private static void GenerateSecondSetOfEdges(ProductStructureInput inputParameters, ProductStructure productStructure,
                                                     XRandom rng, long edgeCount, Dictionary <int, List <KeyValuePair <int, double> > > pkPerI)
        {
            var possibleStartNodes = productStructure.NodesCounter - inputParameters.EndProductCount;

            for (var j = productStructure.Edges.LongCount() + 1; j <= edgeCount; j++)
            {
                var startNodePos             = rng.NextLong(possibleStartNodes) + 1;
                var assemblyLevelOfStartNode = 2;
                while (assemblyLevelOfStartNode < inputParameters.DepthOfAssembly)
                {
                    if (startNodePos <= productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount())
                    {
                        break;
                    }

                    startNodePos -= productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount();
                    assemblyLevelOfStartNode++;
                }

                var u   = rng.NextDouble();
                var sum = 0.0;
                var k   = 0;
                while (k < pkPerI[assemblyLevelOfStartNode].Count - 1)
                {
                    sum += pkPerI[assemblyLevelOfStartNode][k].Value;
                    if (u < sum)
                    {
                        break;
                    }

                    k++;
                }

                var assemblyLevelOfEndNode = pkPerI[assemblyLevelOfStartNode][k].Key;
                var endNodePos             = rng.NextLong(productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1].LongCount());
                var edge = new Edge
                {
                    Start = productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1][startNodePos - 1],
                    End   = productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1][endNodePos]
                };
                edge.End.IncomingEdges.Add(edge);
                productStructure.Edges.Add(edge);
            }
        }
Exemplo n.º 18
0
        private int DetermineNextWorkingMachine(int currentMachine, XRandom rng)
        {
            var u   = rng.NextDouble();
            var sum = 0.0;
            var k   = 0;

            while (k < _cumulatedProbabilities[currentMachine].Count - 1)
            {
                sum += _cumulatedProbabilities[currentMachine][k].Value;
                if (u < sum)
                {
                    break;
                }

                k++;
            }
            return(_cumulatedProbabilities[currentMachine][k].Key);
        }
Exemplo n.º 19
0
    private void CreateWave()
    {
        this.ClearCurrentRoom();
        base.currentRoomID++;
        RoomGenerateBase.Room room = new RoomGenerateBase.Room();
        room.SetRoomID(base.currentRoomID);
        string[] tmxids = null;
        int      num    = (int)GameLogic.Hold.BattleData.Challenge_GetEvent("MatchDefenceTime_get_random_roomid_row");

        switch (num)
        {
        case 0:
            tmxids = GameLogic.Hold.BattleData.GetActiveLevelData(base.currentRoomID).RoomIDs;
            break;

        case 1:
            tmxids = GameLogic.Hold.BattleData.GetActiveLevelData(base.currentRoomID).RoomIDs1;
            break;

        case 2:
            tmxids = GameLogic.Hold.BattleData.GetActiveLevelData(base.currentRoomID).RoomIDs2;
            break;

        default:
        {
            object[] args = new object[] { num };
            SdkManager.Bugly_Report("RoomGenerateMatchDefenceTime.CreateWave", Utils.FormatString("(NotifyConst.MatchDefenceTime.get_random_roomid_row[{0}] is invalid.", args));
            break;
        }
        }
        XRandom random = (XRandom)GameLogic.Hold.BattleData.Challenge_GetEvent("MatchDefenceTime_get_xrandom");
        string  tmxid  = base.RandomTmx(tmxids, random);

        room.SetTmx(tmxid);
        MapCreator.Transfer t = new MapCreator.Transfer {
            roomctrl    = base.roomCtrl,
            roomid      = base.currentRoomID,
            resourcesid = room.ResourcesID,
            tmxid       = room.TMXID,
            delay       = true
        };
        GameLogic.Release.MapCreatorCtrl.CreateMap(t);
    }
        private void GenerateParts(ProductStructureInput inputParameters, ProductStructure productStructure,
                                   List <HashSet <long> > availableNodes, MasterTableArticleType articleTypes, MasterTableUnit units,
                                   M_Unit[] unitCol, XRandom rng)
        {
            bool sampleWorkPlanLength = inputParameters.MeanWorkPlanLength != null &&
                                        inputParameters.VarianceWorkPlanLength != null;
            TruncatedDiscreteNormal truncatedDiscreteNormalDistribution = null;

            if (sampleWorkPlanLength)
            {
                truncatedDiscreteNormalDistribution = new TruncatedDiscreteNormal(1, null,
                                                                                  Normal.WithMeanVariance((double)inputParameters.MeanWorkPlanLength,
                                                                                                          (double)inputParameters.VarianceWorkPlanLength, rng.GetRng()));
            }
            for (var i = 1; i <= inputParameters.DepthOfAssembly; i++)
            {
                productStructure.NodesCounter += GeneratePartsForEachLevel(inputParameters, productStructure, availableNodes,
                                                                           articleTypes, units, unitCol, rng, i, sampleWorkPlanLength, truncatedDiscreteNormalDistribution);
            }
        }
Exemplo n.º 21
0
        public Contains_int(int count)
        {
            value_List    = new List <int>(count);
            value_Array   = new int[count];
            value_HashSet = new HashSet <int>();

            var index = XRandom.Next(0, count);

            for (int i = 0; i < count; i++)
            {
                var tmpValue = XRandom.Next();
                value_List.Add(tmpValue);
                value_Array[i] = tmpValue;
                value_HashSet.Add(tmpValue);

                if (index == i)
                {
                    value_target = tmpValue;
                }
            }
        }
Exemplo n.º 22
0
        public Contains_enum(int count)
        {
            value_List    = new List <EnumContains>(count);
            value_Array   = new EnumContains[count];
            value_HashSet = new HashSet <EnumContains>();

            var index = XRandom.Next(0, count);

            for (int i = 0; i < count; i++)
            {
                var tmpValue = (EnumContains)XRandom.Next(0, 1000);
                value_List.Add(tmpValue);
                value_Array[i] = tmpValue;
                value_HashSet.Add(tmpValue);

                if (index == i)
                {
                    value_target = tmpValue;
                }
            }
        }
        private static M_Unit GeneratePartsForCurrentLevel(ProductStructureInput inputParameters, M_Unit[] unitCol,
                                                           XRandom rng, int i, bool sampleWorkPlanLength, TruncatedDiscreteNormal truncatedDiscreteNormalDistribution,
                                                           HashSet <long> availableNodesOnThisLevel, long j, M_Unit unit, M_ArticleType articleType, bool toPurchase,
                                                           bool toBuild, Dictionary <long, Node> nodesCurrentLevel)
        {
            availableNodesOnThisLevel.Add(j);

            if (i == inputParameters.DepthOfAssembly)
            {
                var pos = rng.Next(unitCol.Length);
                unit = unitCol[pos];
            }

            var node = new Node
            {
                AssemblyLevel = i,
                Article       = new M_Article
                {
                    Name           = "Material " + i + "." + (j + 1),
                    ArticleTypeId  = articleType.Id,
                    CreationDate   = DateTime.Now,
                    DeliveryPeriod = 5,
                    UnitId         = unit.Id,
                    Price          = 10,
                    ToPurchase     = toPurchase,
                    ToBuild        = toBuild
                }
            };

            nodesCurrentLevel[j] = node;
            if (sampleWorkPlanLength && i != inputParameters.DepthOfAssembly)
            {
                node.WorkPlanLength = truncatedDiscreteNormalDistribution.Sample();
            }

            return(unit);
        }
Exemplo n.º 24
0
        public TransitionMatrix GenerateTransitionMatrix(TransitionMatrixInput inputParameters,
                                                         ProductStructureInput inputProductStructure, XRandom rng)
        {
            var jCorrector = 0;
            var matrixSize = inputParameters.WorkingStations.Count;

            if (inputParameters.ExtendedTransitionMatrix)
            {
                matrixSize += 1;
                jCorrector  = 1;
            }
            _piA = new double[matrixSize, matrixSize];
            _piB = new double[matrixSize, matrixSize];

            InitializePiA(inputParameters, rng, matrixSize, jCorrector);
            InitializePiB(inputParameters, inputProductStructure, matrixSize, jCorrector);
            while (Math.Abs(_organizationDegreeA - inputParameters.DegreeOfOrganization) > 0.001)
            {
                Bisection(inputParameters, matrixSize);
            }
            var transitionMatrix = new TransitionMatrix
            {
                Pi = _piA
            };

            return(transitionMatrix);
        }
Exemplo n.º 25
0
        public void StartGeneration(Approach approach, MasterDBContext dbContext, ResultContext resultContext, bool doVerify = false)
        {
            dbContext.Database.EnsureDeleted();
            dbContext.Database.EnsureCreated();

            var rng = new XRandom(approach.Seed);

            var units        = new MasterTableUnit();
            var unitCol      = units.Init(dbContext);
            var articleTypes = new MasterTableArticleType();

            articleTypes.Init(dbContext);

            var productStructureGenerator = new ProductStructureGenerator();
            var productStructure          = productStructureGenerator.GenerateProductStructure(approach.ProductStructureInput,
                                                                                               articleTypes, units, unitCol, rng);

            ArticleInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var articleTable = dbContext.Articles.ToArray();

            MasterTableStock.Init(dbContext, articleTable);

            var transitionMatrixGenerator = new TransitionMatrixGenerator();

            TransitionMatrix = transitionMatrixGenerator.GenerateTransitionMatrix(approach.TransitionMatrixInput,
                                                                                  approach.ProductStructureInput, rng);

            List <ResourceProperty> resourceProperties = approach.TransitionMatrixInput.WorkingStations
                                                         .Select(x => (ResourceProperty)x).ToList();

            var resourceCapabilities = ResourceInitializer.Initialize(dbContext, resourceProperties);

            var operationGenerator = new OperationGenerator();

            operationGenerator.GenerateOperations(productStructure.NodesPerLevel, TransitionMatrix,
                                                  approach.TransitionMatrixInput, resourceCapabilities, rng);
            OperationInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var billOfMaterialGenerator = new BillOfMaterialGenerator();

            billOfMaterialGenerator.GenerateBillOfMaterial(approach.BomInput, productStructure.NodesPerLevel,
                                                           TransitionMatrix, units, rng);
            BillOfMaterialInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var businessPartner = new MasterTableBusinessPartner();

            businessPartner.Init(dbContext);

            var articleToBusinessPartner = new ArticleToBusinessPartnerInitializer();

            articleToBusinessPartner.Init(dbContext, articleTable, businessPartner);


            if (doVerify)
            {
                var productStructureVerifier = new ProductStructureVerifier();
                productStructureVerifier.VerifyComplexityAndReutilizationRation(approach.ProductStructureInput,
                                                                                productStructure);

                if (approach.TransitionMatrixInput.ExtendedTransitionMatrix)
                {
                    var transitionMatrixGeneratorVerifier = new TransitionMatrixGeneratorVerifier();
                    transitionMatrixGeneratorVerifier.VerifyGeneratedData(TransitionMatrix,
                                                                          productStructure.NodesPerLevel, resourceCapabilities);
                }
            }

            //##### TEMP
            var incomingEdgeCount = 0;

            foreach (var level in productStructure.NodesPerLevel)
            {
                foreach (var node in level)
                {
                    incomingEdgeCount += node.Value.IncomingEdges.Count;
                }
            }

            var actualCR = incomingEdgeCount / (1.0 * (productStructure.NodesCounter - productStructure.NodesPerLevel[^ 1].Count));
Exemplo n.º 26
0
 public SurfMocker()
 {
     r = new XRandom();
 }
        private static void DeterminationOfEdgeWeights(ProductStructureInput inputParameters, ProductStructure productStructure, XRandom rng)
        {
            var logNormalDistribution = LogNormal.WithMeanVariance(inputParameters.MeanIncomingMaterialAmount,
                                                                   Math.Pow(inputParameters.StdDevIncomingMaterialAmount, 2), rng.GetRng());

            foreach (var edge in productStructure.Edges)
            {
                edge.Weight = logNormalDistribution.Sample();
            }
        }
Exemplo n.º 28
0
        private double InitializePiACalcCellValue(TransitionMatrixInput inputParameters, int i, int j, int matrixSize, Faculty faculty, XRandom rng, int jCorrector)
        {
            var noiseFactor = 1 + 0.2 * (rng.NextDouble() - 0.5);

            if (inputParameters.ExtendedTransitionMatrix && i == 0 && j + 1 == matrixSize)
            {
                return(0.0);
            }
            if (i < j + jCorrector)
            {
                return(Math.Pow(inputParameters.Lambda, -i + j + jCorrector - 1) / faculty.Calc(-i + j + jCorrector - 1) * noiseFactor);
            }
            return(Math.Pow(inputParameters.Lambda, i - (j + jCorrector) - 1) / (2 * faculty.Calc(i - (j + jCorrector) - 1)) * noiseFactor);
        }
        public void GenerateBillOfMaterial(BillOfMaterialInput inputParameters, List <Dictionary <long, Node> > nodesPerLevel, TransitionMatrix transitionMatrix, MasterTableUnit units, XRandom rng)
        {
            for (var k = 0; k < nodesPerLevel.Count - 1; k++)
            {
                foreach (var article in nodesPerLevel[k].Values)
                {
                    List <List <Edge> > incomingMaterialAllocation = new List <List <Edge> >();
                    foreach (var operation in article.Operations)
                    {
                        incomingMaterialAllocation.Add(new List <Edge>());
                    }

                    foreach (var edge in article.IncomingEdges)
                    {
                        var operationNumber = rng.Next(incomingMaterialAllocation.Count);
                        incomingMaterialAllocation[operationNumber].Add(edge);
                    }

                    List <List <Edge> > possibleSetsForFirstOperation =
                        incomingMaterialAllocation.FindAll(x => x.Count > 0);
                    var         randomSet      = rng.Next(possibleSetsForFirstOperation.Count);
                    List <Edge> firstOperation = possibleSetsForFirstOperation[randomSet];

                    List <List <Edge> > bom = new List <List <Edge> >();
                    incomingMaterialAllocation.Remove(firstOperation);
                    bom.Add(firstOperation);
                    bom.AddRange(incomingMaterialAllocation);

                    for (var i = 0; i < bom.Count; i++)
                    {
                        for (var j = 0; j < bom[i].Count; j++)
                        {
                            var name = "[" + bom[i][j].Start.Article.Name + "] in (" +
                                       article.Operations[i].MOperation.Name + ")";
                            var weight = (decimal)bom[i][j].Weight;
                            if (inputParameters.RoundEdgeWeight || bom[i][j].Start.Article.UnitId == units.PIECES.Id)
                            {
                                weight = Math.Max(1, Decimal.Round(weight));
                            }
                            else
                            {
                                weight = Math.Max(inputParameters.WeightEpsilon, weight);
                            }
                            var articleBom = new M_ArticleBom()
                            {
                                ArticleChildId  = bom[i][j].Start.Article.Id,
                                Name            = name, Quantity = weight,
                                ArticleParentId = article.Article.Id,
                                OperationId     = article.Operations[i].MOperation.Id
                            };
                            article.Operations[i].Bom.Add(articleBom);
                        }
                    }
                }
            }
        }
        private void GenerateFirstSetOfEdgesForDivergingMaterialFlow(ProductStructureInput inputParameters,
                                                                     ProductStructure productStructure, XRandom rng, List <HashSet <long> > availableNodes)
        {
            for (var i = inputParameters.DepthOfAssembly; i >= 2; i--)
            {
                for (long j = 1; j <= productStructure.NodesPerLevel[i - 1].LongCount() /*&& availableNodes[i - 2].LongCount() > 0*/; j++)
                {
                    var endNodePos = rng.NextLong(availableNodes[i - 2].LongCount());
                    var endNode    = availableNodes[i - 2].ToArray()[endNodePos];
                    var edge       = new Edge
                    {
                        Start = productStructure.NodesPerLevel[i - 1][j - 1],
                        End   = productStructure.NodesPerLevel[i - 2][endNode]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                    availableNodes[i - 2].Remove(endNode);
                }
            }

            for (var i = 1; i < inputParameters.DepthOfAssembly; i++)
            {
                var pk = GetCumulatedProbabilitiesPk2(i, inputParameters.DepthOfAssembly);
                foreach (var j in availableNodes[i - 1])
                {
                    var u   = rng.NextDouble();
                    var sum = 0.0;
                    var k   = 0;
                    while (k < pk.Count - 1)
                    {
                        sum += pk[k].Value;
                        if (u < sum)
                        {
                            break;
                        }

                        k++;
                    }

                    var assemblyLevelOfStartNode = pk[k].Key;
                    var posOfNode = rng.NextLong(productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount());
                    var edge      = new Edge
                    {
                        Start = productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1][posOfNode],
                        End   = productStructure.NodesPerLevel[i - 1][j]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                }
            }
        }