Пример #1
0
            public List <MultipartiteWeightedMatch> getMatching(MultipartiteWeightTensor weightTensor, double MergeLowerBound)
            {
                List <MultipartiteWeightedMatch> match_list = new List <MultipartiteWeightedMatch>();

                //each dictionary is a set to be merged heirchically
                List <Dictionary <int, int> > sets = new List <Dictionary <int, int> >();

                //initially all tracks are individually kept in the match list
                for (int i = 0; i < weightTensor.noParts; i++)
                {
                    for (int j = 0; j < weightTensor.getNumPartitionElements(i); j++)
                    {
                        Dictionary <int, int> set = new Dictionary <int, int>();
                        set.Add(i, j);
                        sets.Add(set);
                    }
                }

                //now we heirchically merge two most similar sets
                //until there is no longer any mergable subset

                bool merged     = false;
                int  iterations = 0;

                do
                {
                    merged = false;
                    int    set1Index      = -1;
                    int    set2Index      = -1;
                    double maxSimilarlity = 0;
                    for (int i = 0; i < sets.Count - 1; i++)
                    {
                        /*                       if(i==5 && iterations==1)
                         *                     {
                         *                         Console.WriteLine("Here");
                         *                     }*/
                        Dictionary <int, int> set1 = sets[i];
                        for (int j = i + 1; j < sets.Count; j++)
                        {
                            Dictionary <int, int> set2 = sets[j];
                            if (!setsAreMergable(set1, set2))
                            {
                                continue;
                            }
                            double sim = computeInterParitionWeight(set1, set2, weightTensor);
                            if (sim > maxSimilarlity)
                            {
                                set1Index      = i;
                                set2Index      = j;
                                maxSimilarlity = sim;
                            }
                        }
                    }
                    if (maxSimilarlity > MergeLowerBound)
                    {
                        Dictionary <int, int> set1 = sets[set1Index];
                        Dictionary <int, int> set2 = sets[set2Index];
                        //first merge set2 into set1
                        foreach (KeyValuePair <int, int> entry in set2)
                        {
                            set1.Add(entry.Key, entry.Value);
                        }
                        sets.Remove(set2);
                        merged = true;
                    }
                    iterations++;
                } while (merged);

                foreach (Dictionary <int, int> set in sets)
                {
                    MultipartiteWeightedMatch m = new MultipartiteWeightedMatch();
                    List <int> partitionList    = set.Keys.ToList();
                    partitionList.Sort();

                    foreach (int part in partitionList)
                    {
                        m.update(part, set[part]);
                    }



                    for (int i = 0; i < partitionList.Count - 1; i++)
                    {
                        for (int j = i + 1; j < partitionList.Count; j++)
                        {
                            double val = weightTensor.getWeight(partitionList[i], m.elementList[partitionList[i]], partitionList[j], m.elementList[partitionList[j]]);
                            m.updateWeight(partitionList[i], partitionList[j], val);
                        }
                    }
                    match_list.Add(m);
                }
                return(match_list);
            }
Пример #2
0
            public List <MultipartiteWeightedMatch> getMatching(MultipartiteWeightTensor weightTensor)
            {
                List <MultipartiteWeightedMatch> match_list = new List <MultipartiteWeightedMatch>();

                //each dictionary is a set to be merged heirchically
                List <Dictionary <int, int> > sets = new List <Dictionary <int, int> >(); //this is the paritition

                //initially all tracks are individually kept in the match list
                //e.g. {0-0},{0-1},{0-2},{1-0},{1-1},{1-2},....,{1-4},{2-0},...
                //each element is a set in the paritition
                for (int i = 0; i < weightTensor.noParts; i++)
                {
                    for (int j = 0; j < weightTensor.getNumPartitionElements(i); j++)
                    {
                        Dictionary <int, int> set = new Dictionary <int, int>();
                        set.Add(i, j);
                        sets.Add(set);
                    }
                }


                //now we heirchically merge two most similar sets
                //until there is no longer any mergable subset

                bool merged     = false;
                int  iterations = 0;

                do
                {
                    merged = false;
                    int    set1Index      = -1;
                    int    set2Index      = -1;
                    double maxSimilarlity = 0;
                    for (int i = 0; i < sets.Count - 1; i++)
                    {
                        Dictionary <int, int> set1 = sets[i];
                        for (int j = i + 1; j < sets.Count; j++)
                        {
                            Dictionary <int, int> set2 = sets[j];
                            if (!setsAreMergable(set1, set2)) //check if the sets are mergable (they do not have an input set in common) e.g. {1-1} and {1-2} cannot be merged since they are both from 1.
                            {
                                continue;
                            }
                            double sim = computeInterParitionWeight(set1, set2, weightTensor);
                            if (sim > maxSimilarlity)
                            {
                                set1Index      = i;
                                set2Index      = j;
                                maxSimilarlity = sim;
                            }
                        }
                    }
                    if (maxSimilarlity > 0) //if two mergable sets were found then merge them!
                    {
                        Dictionary <int, int> set1 = sets[set1Index];
                        Dictionary <int, int> set2 = sets[set2Index];
                        //first merge set2 into set1
                        foreach (KeyValuePair <int, int> entry in set2)
                        {
                            set1.Add(entry.Key, entry.Value);
                        }
                        sets.Remove(set2);
                        merged = true;
                    }
                    iterations++;
                } while (merged);

                foreach (Dictionary <int, int> set in sets)
                {
                    MultipartiteWeightedMatch m = new MultipartiteWeightedMatch();
                    List <int> partitionList    = set.Keys.ToList();
                    partitionList.Sort();

                    foreach (int part in partitionList)
                    {
                        m.update(part, set[part]);
                    }



                    for (int i = 0; i < partitionList.Count - 1; i++)
                    {
                        for (int j = i + 1; j < partitionList.Count; j++)
                        {
                            double val = weightTensor.getWeight(partitionList[i], m.elementList[partitionList[i]], partitionList[j], m.elementList[partitionList[j]]);
                            m.updateWeight(partitionList[i], partitionList[j], val);
                        }
                    }
                    match_list.Add(m);
                }
                return(match_list);
            }