Пример #1
0
 public void DnCamThread(Object Obj)
 {
     DnCamThreadSwitch = true;
     DnCamProcessEvent.Reset();
     while (true)
     {
         if (DnCamProcessEvent.IsSet)
         {
             int DnCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(RightDnCamVisionNumAddr);
             if (DnCamStationNum == 0)
             {
                 VisionStateRightDnCamLeft.GrabingImg();
                 LD.Logic.PlcHandle.Instance.WriteValue(RightDnCamGrabedAddr, 1);
                 VisionStateRightDnCamLeft.DoLocal();
                 VisionStateRightDnCamLeft.ShowRlt();
                 RightDnCamLeftLocalRlt = VisionStateRightDnCamLeft.GetLocalRlt();
                 RightDnLeftLocalIsOk   = true;
             }
             else if (DnCamStationNum == 1)
             {
                 VisionStateRightDnCamRight.GrabingImg();
                 LD.Logic.PlcHandle.Instance.WriteValue(RightDnCamGrabedAddr, 1);
                 VisionStateRightDnCamLeft.DoLocal();
                 VisionStateRightDnCamLeft.ShowRlt();
                 RightDnCamLeftLocalRlt = VisionStateRightDnCamLeft.GetLocalRlt();
                 RightDnRightLocalIsOk  = true;
             }
             DnCamProcessEvent.Reset();
             if (!DnCamThreadSwitch)
             {
                 break;
             }
         }
     }
 }
Пример #2
0
 public void DnCamThread(object Obj)
 {
     DncamThreadSwitch = true;
     DnCamProcessEvent.Reset();
     while (true)
     {
         if (DnCamProcessEvent.IsSet)
         {
             int DnCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LeftDnCamVisionNumAddr);
             if (DnCamStationNum == 0)                                           //左下相机左侧定位
             {
                 VisionStateDnLeftCamLeft.GrabingImg();                          //1.0开始采图
                 LD.Logic.PlcHandle.Instance.WriteValue(LeftDnCamGrabedAddr, 1); //2.0告诉PLC采图完成
                 VisionStateDnLeftCamLeft.DoLocal();                             //3.0执行定位
                 VisionStateDnLeftCamLeft.ShowRlt();                             //4.0显示定位结果
                 LeftDnCamLeftLocalResult = VisionStateDnLeftCamLeft.GetLocalRlt();
                 LeftDnCamLeftLocalIsOk   = true;
             }
             else if (DnCamStationNum == 1) //左下相机右侧定位
             {
                 VisionStateDnLeftCamRight.GrabingImg();
                 LD.Logic.PlcHandle.Instance.WriteValue(LeftDnCamGrabedAddr, 1);
                 VisionStateDnLeftCamRight.DoLocal();
                 VisionStateDnLeftCamRight.ShowRlt();
                 LeftDnCamRightLocalResult = VisionStateDnLeftCamRight.GetLocalRlt();
                 LeftDnCamRightLocalIsOk   = true;
             }
         }
         DnCamProcessEvent.Reset();
         if (!DncamThreadSwitch)
         {
             break;
         }
     }
 }
Пример #3
0
        public bool DoLocal()
        {
            FileLib.Logger.Pop("  采图完成开始执行定位:", false, StationDescribe + "运行日志");
            myLocalManager.SetParam(GrabImg, MyVisionPara.localPara);

            myLocalManager.doLocal();
            myLocalrlt =   myLocalManager.GetResult();
            FileLib.Logger.Pop("  定位完成,返回定位结果:", false, StationDescribe + "运行日志");
            return true;
        }
Пример #4
0
        public void UpCamThread(Object Obj)
        {
            UpCamThreadSwitch = true;
            UpCamProcessEvent.Reset();
            while (true)
            {
                if (UpCamProcessEvent.IsSet)
                {
                    int UpCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(UpCamVisionNumAddr);
                    if (UpCamStationNum == 0)
                    {
                        VisionStateUpCamLeftDn.GrabingImg();                          //1.0 开始采图
                        LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1);   //2.0 告诉Plc采图完成
                        VisionStateUpCamLeftDn.DoLocal();                             //3.0 执行定位
                        VisionStateUpCamLeftDn.ShowRlt();                             //4.0 显示定位结果
                        UpCamLeftDnLocalRlt  = VisionStateUpCamLeftDn.GetLocalRlt();  //5.0  获取定位结果
                        UpCamLeftDnLocalIsOk = true;
                    }
                    else if (UpCamStationNum == 1)
                    {
                        VisionStateUpCamRightDn.GrabingImg();
                        LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1);
                        VisionStateUpCamRightDn.DoLocal();
                        VisionStateUpCamRightDn.ShowRlt();
                        UpCamRightDnLocalRlt  = VisionStateUpCamRightDn.GetLocalRlt();
                        UpCamRightDnLocalIsOk = true;
                    }
                    UpCamProcessEvent.Reset();
                }
                else
                {
                    Thread.Sleep(1);
                }
                if (UpCamLeftDnLocalIsOk && UpCamRightDnLocalIsOk && RightDnLeftLocalIsOk && RightDnRightLocalIsOk)
                {
                    //1.0计算胶带当前的定位坐标,相对于示教坐标的偏差;
                    double LeftOffSetX = 0, LeftOffSetY = 0, RightOffSetX = 0, RightOffsetY = 0;
                    LeftOffSetX  = RightDnCamLeftLocalRlt.PosToRot.Col - RightDnCamLeftLocalRlt.TeachPosToRot.Col;
                    LeftOffSetY  = RightDnCamLeftLocalRlt.PosToRot.Row - RightDnCamLeftLocalRlt.TeachPosToRot.Row;
                    RightOffSetX = RightDnCamRightLocalRlt.PosToRot.Col - RightDnCamRightLocalRlt.TeachPosToRot.Col;
                    RightOffsetY = RightDnCamRightLocalRlt.PosToRot.Row - RightDnCamRightLocalRlt.TeachPosToRot.Row;

                    //2.0 用当前的胶带坐标相对于示教的偏移量, 调整Ipad的示教坐标
                    Point2Db TeachIpadPosLeft  = new Point2Db(UpCamLeftDnLocalRlt.TeachPosToRot.Col, UpCamLeftDnLocalRlt.TeachPosToRot.Row);
                    Point2Db TeachIpadPosRight = new Point2Db(UpCamRightDnLocalRlt.TeachPosToRot.Col, UpCamRightDnLocalRlt.TeachPosToRot.Row);
                    TeachIpadPosLeft.Col  = TeachIpadPosLeft.Col + LeftOffSetX;
                    TeachIpadPosLeft.Row  = TeachIpadPosLeft.Row + LeftOffSetY;
                    TeachIpadPosRight.Col = TeachIpadPosRight.Col + RightOffSetX;
                    TeachIpadPosRight.Row = TeachIpadPosRight.Row + RightOffsetY;

                    //3.0 利用调整后的Ipad示教坐标 和 当前的Ipad坐标 计算出 偏移补偿量
                    Point2Db NowIpadLeftPos  = new Point2Db(UpCamLeftDnLocalRlt.PosToRot.Col, UpCamLeftDnLocalRlt.PosToRot.Row);
                    Point2Db NowIpadRightPos = new Point2Db(UpCamRightDnLocalRlt.PosToRot.Col, UpCamRightDnLocalRlt.PosToRot.Row);

                    //4.0计算出偏移量
                    double SystemOffsetX = RightDnLeftVisionPara.localPara.localSetting.Offset_x;
                    double SystemOffsetY = RightDnLeftVisionPara.localPara.localSetting.Offset_y;
                    double SystemOffsetTheta = RightDnLeftVisionPara.localPara.localSetting.Offset_theta;
                    double AddX = 0, AddY = 0, AddTheta = 0;
                    MyVisionBase.CalculateTwoPtPos(NowIpadLeftPos, NowIpadRightPos, TeachIpadPosLeft, TeachIpadPosRight,
                                                   SystemOffsetX, SystemOffsetY, SystemOffsetTheta, out AddX, out AddY, out AddTheta);
                    FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + "  " + AddY.ToString("f3") + "  " +
                                       AddTheta.ToString("f3"), false, "运行日志");

                    int NewAddX = (int)(AddX * 1000);
                    int NewAddY = (int)(AddY * 1000);
                    int NewAddTheta = (int)(AddTheta * 1000);

                    LD.Logic.PlcHandle.Instance.WriteValue(RightDnCamVisionFinishAddr, 1);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_X, -NewAddX);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_Y, NewAddY);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_R, NewAddTheta);
                }
            }
        }
Пример #5
0
        private void UpCamThread(Object Obj)
        {
            UpCamThreadSwitch = true;
            UpCamProcessEvent.Reset();
            while (true)
            {
                if (UpCamProcessEvent.IsSet)
                {
                    int UpCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(UpCamVisionNumAddr);
                    if (UpCamStationNum == 0) //上相机定位左上角
                    {
                        //1.0开始采图
                        VisionStateBaseUpCamLeftUp.GrabingImg();
                        //2.0告诉PLC采图完成
                        LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1);
                        //3.0执行定位
                        VisionStateBaseUpCamLeftUp.DoLocal();
                        //4.0显示定位结果
                        VisionStateBaseUpCamLeftUp.ShowRlt();
                        //5.0获取定位结果
                        UpCamLeftUpLocalRlt  = VisionStateBaseUpCamLeftUp.GetLocalRlt();
                        UpCamLeftUpLocalIsok = true;
                    }
                    else if (UpCamStationNum == 1)//上相机定位右上角
                    {
                        VisionStateBaseUpCamRightUp.GrabingImg();
                        LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1);
                        VisionStateBaseUpCamRightUp.DoLocal();
                        VisionStateBaseUpCamRightUp.ShowRlt();
                        UpCamRightUpLocalRlt  = VisionStateBaseUpCamLeftUp.GetLocalRlt();
                        UpCamRightUpLocalIsOk = true;
                    }
                    UpCamProcessEvent.Reset();
                }
                else
                {
                    Thread.Sleep(1);
                }
                if (UpCamLeftUpLocalIsok && UpCamRightUpLocalIsOk && LeftDnCamLeftLocalIsOk && LeftDnCamRightLocalIsOk)
                {
                    //1.0计算胶带当前的定位坐标,相对于示教坐标的偏差;
                    double LeftOffSetX = 0, LeftOffSetY = 0, RightOffSetX = 0, RightOffsetY = 0;
                    LeftOffSetX  = LeftDnCamLeftLocalResult.PosToRot.Col - LeftDnCamLeftLocalResult.TeachPosToRot.Col;
                    LeftOffSetY  = LeftDnCamLeftLocalResult.PosToRot.Row - LeftDnCamLeftLocalResult.TeachPosToRot.Row;
                    RightOffSetX = LeftDnCamRightLocalResult.PosToRot.Col - LeftDnCamRightLocalResult.TeachPosToRot.Col;
                    RightOffsetY = LeftDnCamRightLocalResult.PosToRot.Row - LeftDnCamRightLocalResult.TeachPosToRot.Row;
                    //2.0 用当前的胶带坐标相对于示教的偏移量, 调整Ipad的示教坐标
                    Point2Db TeachIpadPosLeft  = new Point2Db(UpCamLeftUpLocalRlt.TeachPosToRot.Col, UpCamLeftUpLocalRlt.TeachPosToRot.Row);
                    Point2Db TeachIpadPosRight = new Point2Db(UpCamRightUpLocalRlt.TeachPosToRot.Col, UpCamRightUpLocalRlt.TeachPosToRot.Row);
                    TeachIpadPosLeft.Col  = TeachIpadPosLeft.Col + LeftOffSetX;
                    TeachIpadPosLeft.Row  = TeachIpadPosLeft.Row + LeftOffSetY;
                    TeachIpadPosRight.Col = TeachIpadPosRight.Col + RightOffSetX;
                    TeachIpadPosRight.Row = TeachIpadPosRight.Row + RightOffsetY;
                    //3.0 利用调整后的Ipad示教坐标 和 当前的Ipad坐标 计算出 偏移补偿量
                    Point2Db NowIpadLeftPos  = new Point2Db(UpCamLeftUpLocalRlt.PosToRot.Col, UpCamLeftUpLocalRlt.PosToRot.Row);
                    Point2Db NowIpadRightPos = new Point2Db(UpCamRightUpLocalRlt.PosToRot.Col, UpCamRightUpLocalRlt.PosToRot.Row);
                    //4.0计算出偏移量
                    double AddX = 0, AddY = 0, AddTheta = 0;
                    MyVisionBase.CalculateThreeTapePos(NowIpadLeftPos, NowIpadRightPos, TeachIpadPosLeft, TeachIpadPosRight, out AddX, out AddY, out AddTheta);
                    FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + "  " + AddY.ToString("f3") + "  " + AddTheta.ToString("f3"), false, "运行日志");
                    int SystemOffSetX = 0, SystemOffsetY = 0;
                    SystemOffSetX = (int)(LeftDnCamLeftVisionPara.localPara.localSetting.Offset_x * 1000); //系统误差补偿
                    SystemOffsetY = (int)(LeftDnCamLeftVisionPara.localPara.localSetting.Offset_y * 1000);
                    int NewAddX     = (int)(AddX * 1000) + SystemOffSetX;
                    int NewAddY     = (int)(AddY * 1000) + SystemOffsetY;
                    int NewAddTheta = (int)(AddTheta * 1000);
                    LD.Logic.PlcHandle.Instance.WriteValue(LeftDnCamVisionFinishAddr, 1);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_X, NewAddX);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_Y, -NewAddY); //移动屏幕
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_R, NewAddTheta);

                    //5.0 清空此次定位的数据,进入下次定位
                    UpCamLeftUpLocalIsok    = false;
                    UpCamRightUpLocalIsOk   = false;
                    LeftDnCamLeftLocalIsOk  = false;
                    LeftDnCamRightLocalIsOk = false;
                }
                if (!UpCamThreadSwitch)
                {
                    break;
                }
            }
        }
Пример #6
0
        private void IpadLcoalThread(object Obj)
        {
            FeederThreadSwitch = true;
            while (true)
            {
                if (FeerderCamTrigEvent.IsSet)
                {
                    int StateNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(FeederCamStateNumAddr);
                    if (StateNum == 0) //Ipad左上角
                    {
                        VisionStateLeftUp.GrabingImg();
                        LD.Logic.PlcHandle.Instance.WriteValue(FeederCamGrabedAddr, 1);
                        VisionStateLeftUp.DoLocal();
                        VisionStateLeftUp.ShowRlt();
                        LeftUpLocalRlt  = VisionStateLeftUp.GetLocalRlt();
                        LeftUpLocalIsOK = true;
                    }
                    else if (StateNum == 1)  //Ipad右下角
                    {
                        VisionStateRightDn.GrabingImg();
                        LD.Logic.PlcHandle.Instance.WriteValue(FeederCamGrabedAddr, 1);
                        VisionStateRightDn.DoLocal();
                        VisionStateRightDn.ShowRlt();
                        RightDnLocalRlt  = VisionStateRightDn.GetLocalRlt();
                        RightDnLocalIsOk = true;
                    }
                }
                if (LeftUpLocalIsOK && RightDnLocalIsOk)
                {
                    //1.0Ipad放置时的示教坐标
                    Point2Db IpadLeftUpTeachPos  = new Point2Db(LeftUpLocalRlt.TeachPosToRot.Col, LeftUpLocalRlt.TeachPosToRot.Row);
                    Point2Db IpadRightDnTeachPos = new Point2Db(RightDnLocalRlt.TeachPosToRot.Col, RightDnLocalRlt.TeachPosToRot.Row);

                    //2.0Ipad的当前坐标
                    Point2Db IpadLeftUpNowPos  = new Point2Db(LeftUpLocalRlt.PosToRot.Col, LeftUpLocalRlt.PosToRot.Row);
                    Point2Db IpadRightDnNowPos = new Point2Db(RightDnLocalRlt.PosToRot.Col, RightDnLocalRlt.PosToRot.Row);

                    //3.0计算出偏移量
                    double AddX = 0, AddY = 0, AddTheta = 0;
                    MyVisionBase.CalculateThreeTapePos(IpadLeftUpNowPos, IpadRightDnNowPos, IpadLeftUpTeachPos, IpadRightDnTeachPos, out AddX, out AddY, out AddTheta);
                    FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + "  " + AddY.ToString("f3") + "  " + AddTheta.ToString("f3"), false, "运行日志");

                    int SystemOffSetX = 0, SystemOffsetY = 0;
                    SystemOffSetX = (int)(LeftUpVisionPara.localPara.localSetting.Offset_x * 1000); //系统误差补偿
                    SystemOffsetY = (int)(LeftUpVisionPara.localPara.localSetting.Offset_y * 1000); //系统误差补偿
                    int NewAddX     = (int)(AddX * 1000) + SystemOffSetX;
                    int NewAddY     = (int)(AddY * 1000) + SystemOffsetY;
                    int NewAddTheta = (int)(AddTheta * 1000);
                    LD.Logic.PlcHandle.Instance.WriteValue(FeederCamVisionFinishAddr, 1);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_X, NewAddX);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_Y, NewAddY); //移动屏幕
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_R, NewAddTheta);

                    //4.0 清空此次定位的数据,进入下次定位
                    LeftUpLocalIsOK  = false;
                    RightDnLocalIsOk = false;
                }
                Thread.Sleep(1);
                if (!FeederThreadSwitch)
                {
                    break;
                }
            }
        }
Пример #7
0
        public static void Run(SoftwareGraphLearningParameters parameters)
        {
            Build.Do();

            var graphs = new List <IGWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> >();

            #region Graphen erzeugen

            var erdösGraphCreator    = new ErdösGraphCreator();
            var categoryGraphCreator = new CategoryGraphCreator();

            for (int i = 0; i < parameters.NumberOfGraphs; i++)
            {
                var newGraph = erdösGraphCreator.CreateGraph(new ErdösGraphCreationParameter(parameters));
                // Kategoriengraph erzeugen
                categoryGraphCreator.CreateCategoryGraph(newGraph);

                graphs.Add(newGraph);

                //var graph3D = newGraph.Wrap3D();
                //new ShowGraph3D(graph3D).Request();
            }



            #endregion

            #region Beobachtungen erzeugen
            // TODO: Nach welchem Vorgehen Beobachtungen erzeugen?
            // erstmal: für jede Kategorie: zufällig x [0,1): Prob(0) = x, Prob(1) = 1-x

            for (int i = 0; i < parameters.NumberOfGraphs; i++)
            {
                var graph = graphs[i];
                // Beobachtung für graph erzeugen
                foreach (var node in graph.Nodes)
                {
                    var categoryGraph = graph.Data.CategoryGraph;
                    var category      = categoryGraph.Nodes.ToList().Find(catNode => catNode.Data.Category == node.Data.Category);

                    double probability = CodeBase.BaseProgram.Random.NextDouble();
                    if (probability <= category.Data.ObservationProbabilty)
                    {
                        node.Data.Observation = 0;
                    }
                    else
                    {
                        node.Data.Observation = 1;
                    }
                }
            }

            //information about graph

            /*
             * var graphView = new GraphView();
             * foreach (var graph in graphs)
             * {
             *  graphView.GetGraphInfo(graph);
             *
             * } */



            #endregion

            #region Training

            // zwei Parameter: Korrelationsparameter || Konformitätsparameter
            // zusätzliche parameter (a (negativ), b) (vorgegeben in SoftwareGraphLearningParameters)
            // Zielfunktion setzt sich aus zwei Zielen zusammen:
            // Ziel 1: Homogenität: erstmal: Für jede Kategorie: Score := a * (Math.Abs(0.95 - homogenityRatio))
            // Ziel 2: Unabhängigkeit: erstmal: Für jede Kategorie: Score += b, falls
            // Ziel 3: Korrelation mit lokalen Beobachtungen
            // Math.Sign([Mittelwert Knotenscore] - 0.5) == Math.Sign([Mittelwert Knotenlabeling] - 0.5)
            // Ziel 3: Korrelation



            //in results sind die durchschnittl homogenitäten der graphen für die 10 * 10 datenpunkte gespeichert
            var results = new List <LocalResult>();
            for (int k = 1; k <= 10; k++)
            {
                for (int l = 1; l <= 10; l++)
                {
                    var conformity  = k * 0.1;
                    var correlation = l * 0.1;
                    var isingModel  = new IsingModel(conformity, correlation);
                    //in resultstemp sind homogenitäten für die graphen bei gleicher correlation + conformity
                    var resultsTemp = new List <LocalResult>();
                    int counter     = 0;
                    foreach (var graph in graphs)
                    {
                        var localResult = new LocalResult(parameters.NumberCategories, conformity, correlation);

                        #region homogenities normal

                        // anhand der Observation & Korrelation/Konformität CRF-Scores berechnen
                        // Berechne Scores für nodes und edges
                        isingModel.CreateCRFScore(graph);

                        // Viterbiheuristik starten
                        var request = new SolveInference(graph, null, parameters.NumberLabels);
                        request.RequestInDefaultContext();

                        // sammeln der ergebnisse
                        var resultingLabeling = request.Solution.Labeling;

                        //labeling auf nodes mappen
                        var nodes = graph.Nodes.ToList();
                        foreach (var node in nodes)
                        {
                            node.Data.AssignedLabel = resultingLabeling[node.GraphId];
                        }

                        //homogenität berechnen -> in localResult speichern
                        var categoryGraph = graph.Data.CategoryGraph;
                        //durch jede kategorie gehen
                        foreach (var catNode in categoryGraph.Nodes)
                        {
                            int amountZeroLabeled = 0;
                            //für jeden knoten in aktueller kategorie, anzahl 0 labels zählen
                            foreach (var node in catNode.Data.Nodes)
                            {
                                if (node.Data.AssignedLabel == 0)
                                {
                                    amountZeroLabeled++;
                                }
                            }
                            //homogenität = max(a; 1-a) a = anteil mit 0 gelabelt
                            var homogenityRatio = Math.Max((amountZeroLabeled * 1.0) / catNode.Data.NumberNodes,
                                                           1 - (amountZeroLabeled * 1.0) / catNode.Data.NumberNodes);
                            //homgenität speichern in homogenity array
                            localResult.Homs[catNode.Data.Category] = homogenityRatio;
                        }
                        #endregion

                        #region distinction isolated

                        //distinction isoliert berechnen

                        foreach (var edge in graph.Edges)
                        {   //set score of all inter edges to 0
                            if (edge.Data.Type == EdgeType.Inter)
                            {
                                edge.Data.Scores = new double[2, 2] {
                                    { 0, 0 }, { 0, 0 }
                                };
                            }
                        }
                        // Viterbiheuristik starten
                        request = new SolveInference(graph, null, parameters.NumberLabels);
                        request.RequestInDefaultContext();

                        // sammeln der ergebnisse
                        resultingLabeling = request.Solution.Labeling;

                        //labeling auf nodes mappen
                        nodes = graph.Nodes.ToList();
                        foreach (var node in nodes)
                        {
                            node.Data.LabelTemp = resultingLabeling[node.GraphId];
                        }

                        categoryGraph = graph.Data.CategoryGraph;
                        //durch jede kategorie gehen
                        foreach (var catNode in categoryGraph.Nodes)
                        {
                            int amountDifferentLabeled = 0;
                            //für jede kategorie, anzahl unterschiedlich gelabelter knoten zählen
                            foreach (var node in catNode.Data.Nodes)
                            {
                                if (node.Data.AssignedLabel != node.Data.LabelTemp)
                                {
                                    amountDifferentLabeled++;
                                }
                            }
                            //distinctRatio = anteil der ungleich gelabelten nodes
                            var distinctRatio = (amountDifferentLabeled * 1.0) / catNode.Data.NumberNodes;
                            //distinctRatio in distinction array speichern
                            localResult.Distincts[catNode.Data.Category] = distinctRatio;
                        }

                        #endregion

                        resultsTemp.Add(localResult);

                        if (counter == 0)
                        {
                            graph.SaveAsJSON("exampleGraph_" + k + "_" + l + ".txt");
                            //var graph3D = graph.Wrap3D();
                            //new ShowGraph3D(graph3D).Request();
                        }
                        counter++;
                    }//end of foreach graph in graphs

                    //jetzt durchschnittswerte für alle in resultsTemp berechnen
                    //und diese durchschnitte in results speichern
                    var averageResult = new LocalResult(parameters.NumberCategories, conformity, correlation);

                    //values aufaddieren
                    foreach (var localresult in resultsTemp)
                    {
                        averageResult.AddValues(localresult);
                    }
                    //durchschnitte für kategorien
                    for (int i = 0; i < averageResult.Homs.Length; i++)
                    {
                        averageResult.Homs[i]      /= resultsTemp.Count;
                        averageResult.Distincts[i] /= resultsTemp.Count;
                    }
                    //gesamtdurchschnitte
                    double avgHomogenity  = 0;
                    double avgDistinction = 0;
                    for (int i = 0; i < averageResult.Homs.Length; i++)
                    {
                        avgHomogenity  += averageResult.Homs[i];
                        avgDistinction += averageResult.Distincts[i];
                    }
                    avgHomogenity  /= averageResult.Homs.Length;
                    avgDistinction /= averageResult.Distincts.Length;
                    averageResult.AvgHomogenity  = avgHomogenity;
                    averageResult.AvgDistinction = avgDistinction;
                    averageResult.ResultValue    = avgHomogenity + (1 - avgDistinction);

                    //ausgabe
                    Log.Post("Konformität: " + conformity + " - Korrelation: " + correlation + "   ", LogCategory.Result);
                    Log.Post("Avg Homogenity: " + averageResult.AvgHomogenity, LogCategory.Result);
                    Log.Post("Avg Distinction: " + averageResult.AvgDistinction, LogCategory.Result);
                    Log.Post(Environment.NewLine, LogCategory.Result);

                    results.Add(averageResult);
                }
            }

            /*  Erwartungen:
             *
             *  1) gleiche Werte in allen Communities
             *  2) Homogenität ansteigend in Correlation
             *
             *
             * */

            // Auswertung der Homogenität und Unabhängigkeit

            var bestResult = results.MaxEntry(r => r.ResultValue);

            Log.Post("Exhaustive Search Result:");
            Log.Post("conformity: " + bestResult.Conformity);
            Log.Post("correlation: " + bestResult.Correlation);


            bestResult.SaveAsJSON(@"..\..\bestResult.txt");
            results.SaveAsJSON(@"..\..\results.txt");

            #endregion


            #region OLM


            var con = bestResult.Conformity;
            var cor = bestResult.Correlation;

            //create referenceLabeling for best parameters
            var isingModell = new IsingModel(con, cor);

            foreach (var graph in graphs)
            {
                isingModell.CreateCRFScore(graph);
                var request = new SolveInference(graph, null, parameters.NumberLabels);
                request.RequestInDefaultContext();
                graph.Data.ReferenceLabeling = request.Solution.Labeling;
            }

            var req = new OLMRequest(OLMVariant.Default, graphs);
            req.BasisMerkmale.AddRange(new IsingMerkmalNode(), new IsingMerkmalEdge());
            req.LossFunctionValidation = LossFunction;
            req.MaxIterations          = 100;

            req.RequestInDefaultContext();

            double[] olmWeights = req.Result.ResultingWeights;


            Log.Post("OLM Result: ");
            for (int i = 0; i < olmWeights.Length; i++)
            {
                Log.Post(olmWeights[i] + "");
            }
            #endregion
        }//end of Do Method