public bool Belongs(PrivacyPreservingLandmark ppl)
 {
     if (ppl.index == index)
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        static public PrivacyPreservingLandmark MergeList(List <PrivacyPreservingLandmark> lPPLandmark)
        {
            PrivacyPreservingLandmark firstLandmark = lPPLandmark.ElementAt(0);

            for (int i = 1; i < lPPLandmark.Count; i++)
            {
                firstLandmark.Merge(lPPLandmark.ElementAt(i));
            }
            return(firstLandmark);
        }
Beispiel #3
0
 public void Merge(PrivacyPreservingLandmark ppLandmark)
 {
     if (!ppLandmark.isPublic)
     {
         isPublic = false;
     }
     foreach (var item in ppLandmark.EncryptedLandmark)
     {
         if (item.Value != null)
         {
             if (EncryptedLandmark[item.Key] == null)
             {
                 EncryptedLandmark[item.Key] = item.Value;
             }
             else
             {
                 // if (!isPublic)
                 //    isPublic = false;
                 string   name = item.Key;
                 Landmark l    = item.Value;
                 if (EncryptedLandmark[name] == null)
                 {
                     l.index = index;
                     EncryptedLandmark[name] = l;
                 }
                 else
                 {
                     foreach (var fact in l.facts)
                     {
                         if (!EncryptedLandmark[name].facts.ContainsKey(fact.Key))
                         {
                             EncryptedLandmark[name].AddFact(fact.Key, fact.Value);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #4
0
 public bool Equals(PrivacyPreservingLandmark l)
 {
     foreach (var item in EncryptedLandmark)
     {
         if (item.Value != null && l.EncryptedLandmark[item.Key] == null)
         {
             return(false);
         }
         if (item.Value == null && l.EncryptedLandmark[item.Key] != null)
         {
             return(false);
         }
         if (item.Value == null && l.EncryptedLandmark[item.Key] == null)
         {
             continue;
         }
         if (!item.Value.Identical(l.EncryptedLandmark[item.Key]))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #5
0
        public static string Comparer(PrivacyPreservingLandmark ppl1, PrivacyPreservingLandmark ppl2)
        {
            List <GroundedPredicate> gp1List = new List <GroundedPredicate>();
            List <GroundedPredicate> gp2List = new List <GroundedPredicate>();

            if (ppl1.isPublic == false || ppl1.isPublic == false)
            {
                return("Can't Comparer");
            }
            foreach (string name in m_agents)
            {
                if (ppl1.EncryptedLandmark[name] != null)
                {
                    foreach (GroundedPredicate gp in ppl1.EncryptedLandmark[name].facts.Keys)
                    {
                        gp1List.Add(gp);
                    }
                }
                if (ppl2.EncryptedLandmark[name] != null)
                {
                    foreach (GroundedPredicate gp in ppl2.EncryptedLandmark[name].facts.Keys)
                    {
                        gp2List.Add(gp);
                    }
                }
            }
            bool identical = true;
            bool contain   = false;

            foreach (GroundedPredicate gp in gp1List)
            {
                if (!gp2List.Contains(gp))
                {
                    identical = false;
                }
                else
                {
                    contain = true;
                }
            }
            foreach (GroundedPredicate gp in gp2List)
            {
                if (!gp1List.Contains(gp))
                {
                    identical = false;
                }
                else
                {
                    contain = true;
                }
            }
            if (identical)
            {
                return("Identical");
            }
            if (contain)
            {
                if (gp1List.Count < gp2List.Count)
                {
                    return("First");
                }
                else
                {
                    return("Second");
                }
            }
            return("Differents");
        }
Beispiel #6
0
 public PPOrder(string typ, PrivacyPreservingLandmark l1, PrivacyPreservingLandmark l2)
 {
     type      = typ;
     lendmark1 = l1;
     lendmark2 = l2;
 }
Beispiel #7
0
        public static List <Agent> Landmarks_Detection(List <Agent> m_agents, bool full)
        {
            agents = m_agents;
            PrivacyPreservingLandmark.m_agents = new List <string>();
            foreach (Agent ag in agents)
            {
                PrivacyPreservingLandmark.m_agents.Add(ag.name);
            }

            necessaryPPOrders          = new List <PPOrder>();
            PrivacyPreservingLandmarks = new List <PrivacyPreservingLandmark>();
            Queue <PrivacyPreservingLandmark> PrivacyPreservingQueue = new Queue <PrivacyPreservingLandmark>();



            foreach (Agent agent in agents)
            {
                //agent.FirstIteration();
                List <PrivacyPreservingLandmark> tmp = agent.FirstIteration();
                if (full)
                {
                    agent.fullDetection();
                }
                foreach (var item in tmp)
                {
                    if (!PrivacyPreservingLandmarks.Contains(item))
                    {
                        if (item.toDevelop)
                        {
                            PrivacyPreservingQueue.Enqueue(item);
                            PrivacyPreservingLandmarks.Add(item);
                        }

                        else
                        {
                            PrivacyPreservingQueue.Enqueue(item);
                            PrivacyPreservingLandmarks.Add(item);
                        }
                    }
                }
            }

            while (PrivacyPreservingQueue.Count > 0)
            {
                PrivacyPreservingLandmark ppLandmark = PrivacyPreservingQueue.Dequeue();
                foreach (Agent agent in agents)
                {
                    agent.Reset();
                }

                KeyValuePair <Landmark, string> ans = new KeyValuePair <Landmark, string>();

                foreach (Agent agent in agents)
                {
                    agent.SetLandmarkToExplorer(ppLandmark);
                }


                HashSet <GroundedPredicate> publicSet = new HashSet <GroundedPredicate>();

                foreach (Agent agent in agents)
                {
                    HashSet <GroundedPredicate> tmp = agent.Detection();
                    foreach (var gp in tmp)
                    {
                        if (!publicSet.Contains(gp))
                        {
                            publicSet.Add(gp);
                        }
                    }
                }

                bool flag2 = true;
                while (flag2)
                {
                    flag2 = false;
                    foreach (Agent agent in agents)
                    {
                        HashSet <GroundedPredicate> tmp = agent.WhatYoCanGet(publicSet);

                        foreach (var gp in tmp)
                        {
                            if (!publicSet.Contains(gp))
                            {
                                publicSet.Add(gp);
                                flag2 = true;
                            }
                        }
                    }
                }

                List <Agent> relevantAgents = new List <Agent>();

                foreach (Agent agent in agents)
                {
                    List <Action> lAchievers = agent.CanGet();
                    if (lAchievers != null)
                    {
                        relevantAgents.Add(agent);
                        ppLandmark.SetAchievers(agent.name, lAchievers);
                    }
                    else
                    {
                        ppLandmark.SetAchievers(agent.name, lAchievers);
                        // ppLandmark.RemoveAgent(agent.name);
                    }
                }
                if (ppLandmark.ToString().Equals("Empty"))
                {
                    PrivacyPreservingLandmarks.Remove(ppLandmark);
                    continue;
                }
                ppLandmark.TellAboutPublic(agents);
                if (ppLandmark.toDevelop)
                {
                    if (relevantAgents.Count == 1)
                    {
                        List <PrivacyPreservingLandmark> newPPLandmarks = relevantAgents.ElementAt(0).DetectNewLandmarks();

                        foreach (PrivacyPreservingLandmark ppl in newPPLandmarks)
                        {
                            bool insert = true;
                            foreach (PrivacyPreservingLandmark ppl2 in PrivacyPreservingLandmarks)
                            {
                                string str = PrivacyPreservingLandmark.Comparer(ppl, ppl2);
                                if (str == "First")
                                {
                                    PrivacyPreservingLandmarks.Remove(ppl2);
                                    List <PPOrder> delOrders = new List <PPOrder>();
                                    foreach (PPOrder order in necessaryPPOrders)
                                    {
                                        if ((order.lendmark1.Equals(ppl2)) || (order.lendmark2.Equals(ppl2)))
                                        {
                                            delOrders.Add(order);
                                        }
                                    }
                                    foreach (PPOrder ppo in delOrders)
                                    {
                                        necessaryPPOrders.Remove(ppo);
                                    }
                                    break;
                                }
                                if (str == "Second")
                                {
                                    insert = false;
                                    break;
                                }
                                if (str == "Identical")
                                {
                                    insert = false;
                                    break;

                                    insert = false;
                                    PPOrder tmpNecessaryOrder = new PPOrder("greedy-necessary", ppl2, ppLandmark);
                                    necessaryPPOrders.Add(tmpNecessaryOrder);
                                    break;
                                }
                            }
                            if (insert)
                            {
                                PrivacyPreservingLandmarks.Add(ppl);
                                PrivacyPreservingQueue.Enqueue(ppl);
                                PPOrder necessaryOrder = new PPOrder("greedy-necessary", ppl, ppLandmark);
                                necessaryPPOrders.Add(necessaryOrder);
                            }
                        }
                    }
                    else
                    {
                        List <PrivacyPreservingLandmark> newPPLandmarks;
                        Dictionary <string, List <PrivacyPreservingLandmark> > propNameToLandmarks = new Dictionary <string, List <PrivacyPreservingLandmark> >();
                        foreach (Agent relevantAget in relevantAgents)
                        {
                            newPPLandmarks = relevantAget.DetectNewLandmarks();

                            foreach (PrivacyPreservingLandmark ppl in newPPLandmarks)
                            {
                                if (!propNameToLandmarks.ContainsKey(ppl.type))
                                {
                                    propNameToLandmarks.Add(ppl.type, new List <PrivacyPreservingLandmark>());
                                }
                                propNameToLandmarks[ppl.type].Add(ppl);
                            }
                        }
                        foreach (List <PrivacyPreservingLandmark> lppLandmarks in propNameToLandmarks.Values)
                        {
                            if (lppLandmarks.Count == relevantAgents.Count)
                            {
                                PrivacyPreservingLandmark tmpLandmark = PrivacyPreservingLandmark.MergeList(lppLandmarks);
                                bool insert = true;
                                foreach (PrivacyPreservingLandmark ppl2 in PrivacyPreservingLandmarks)
                                {
                                    string str = PrivacyPreservingLandmark.Comparer(tmpLandmark, ppl2);
                                    if (str == "First")
                                    {
                                        PrivacyPreservingLandmarks.Remove(ppl2);
                                        List <PPOrder> delOrders = new List <PPOrder>();
                                        foreach (PPOrder order in necessaryPPOrders)
                                        {
                                            if ((order.lendmark1.Equals(ppl2)) || (order.lendmark2.Equals(ppl2)))
                                            {
                                                delOrders.Add(order);
                                            }
                                        }
                                        foreach (PPOrder ppo in delOrders)
                                        {
                                            necessaryPPOrders.Remove(ppo);
                                        }
                                        break;
                                    }
                                    if (str == "Second")
                                    {
                                        insert = false;
                                        break;
                                    }
                                    if (str == "Identical")
                                    {
                                        insert = false;
                                        break;
                                        insert = false;
                                        PPOrder tmpNecessaryOrder = new PPOrder("greedy-necessary", ppl2, ppLandmark);
                                        necessaryPPOrders.Add(tmpNecessaryOrder);
                                        break;
                                    }
                                }
                                if (insert)
                                {
                                    PrivacyPreservingLandmarks.Add(tmpLandmark);
                                    PrivacyPreservingQueue.Enqueue(tmpLandmark);
                                    PPOrder necessaryOrder = new PPOrder("greedy-necessary", tmpLandmark, ppLandmark);
                                    necessaryPPOrders.Add(necessaryOrder);
                                }
                            }
                        }
                    }
                }
            }
            int count = 0;

            foreach (var ppl in PrivacyPreservingLandmarks)
            {
                ppl.SetIndex(count);
                count++;
            }
            //List<Order> allReasonableorders = new List<Order>();
            Dictionary <string, List <Order> > agentROrder = new Dictionary <string, List <Order> >();

            foreach (Agent agent in agents)
            {
                List <Landmark>            lLandmarks      = new List <Landmark>();
                List <Order>               necessaryOrders = new List <Order>();
                Dictionary <int, Landmark> mapTable        = new Dictionary <int, Landmark>();
                foreach (PrivacyPreservingLandmark ppLandmark in PrivacyPreservingLandmarks)
                {
                    Landmark l = ppLandmark.GetAgentLandmark(agent.name);
                    lLandmarks.Add(l);
                    mapTable.Add(l.index, l);
                }
                foreach (PPOrder order in necessaryPPOrders)
                {
                    if ((mapTable.ContainsKey(order.lendmark1.index)) && (mapTable.ContainsKey(order.lendmark2.index)))
                    {
                        Landmark l1       = mapTable[order.lendmark1.index];
                        Landmark l2       = mapTable[order.lendmark2.index];
                        Order    newOrder = new Order("greedy-necessary", l1, l2);
                        necessaryOrders.Add(newOrder);
                    }
                }
                // PrivacyPreservingLandmarks.ElementAt(0).ToString();
                List <Order> ans = agent.FindReasonableOrdering(lLandmarks, necessaryOrders, agents);
                agentROrder.Add(agent.name, ans);

                /* foreach (Order o in ans)
                 * {
                 *   if (!allReasonableorders.Contains(o))
                 *   {
                 *       allReasonableorders.Add(o);
                 *   }
                 *
                 * }*/
            }
            Dictionary <int, PrivacyPreservingLandmark> mapPPlandmark = new Dictionary <int, PrivacyPreservingLandmark>();

            foreach (PrivacyPreservingLandmark ppLandmark in PrivacyPreservingLandmarks)
            {
                mapPPlandmark.Add(ppLandmark.index, ppLandmark);
            }
            Dictionary <string, List <Order> > newAgentROrder = new Dictionary <string, List <Order> >();

            foreach (Agent agent in agents)
            {
                List <Order> localOrder = new List <Order>(agentROrder[agent.name]);
                foreach (var item in agentROrder)
                {
                    if (item.Key.Equals(agent.name))
                    {
                        continue;
                    }
                    foreach (Order rOrder in item.Value)
                    {
                        if (!localOrder.Contains(rOrder))
                        {
                            PrivacyPreservingLandmark ppl = mapPPlandmark[rOrder.lendmark2.index];
                            if (!ppl.achieversAgents.Contains(agent.name))
                            {
                                localOrder.Add(rOrder);
                            }
                            else
                            {
                                //localOrder.Add(rOrder);
                                Console.WriteLine(".............chack..............");
                            }
                        }
                    }
                }
                List <Order> del = new List <Order>();
                foreach (Order o in localOrder)
                {
                    Order newOrder = new Order("Reasonable", o.lendmark2, o.lendmark1);
                    if (localOrder.Contains(newOrder))
                    {
                        del.Add(newOrder);
                        del.Add(o);
                    }
                }
                foreach (Order dellOrder in del)
                {
                    if (localOrder.Contains(dellOrder))
                    {
                        localOrder.Remove(dellOrder);
                    }
                }
                newAgentROrder.Add(agent.name, localOrder);
                //allReasonableorders = new List<Order>();
                //agent.SetReasonableOrdering(localOrder);
            }
            List <Order> allReasonableorders = new List <Order>();

            if (newAgentROrder.Count > 0)
            {
                List <Order> first = newAgentROrder.ElementAt(0).Value;
                foreach (Order o in first)
                {
                    bool isShare = true;
                    foreach (var item in newAgentROrder)
                    {
                        if (!item.Value.Contains(o))
                        {
                            isShare = false;
                            continue;
                        }
                    }
                    if (isShare)
                    {
                        allReasonableorders.Add(o);
                    }
                }
            }
            foreach (Agent agent in agents)
            {
                //allReasonableorders = new List<Order>();
                agent.SetReasonableOrdering(allReasonableorders);
            }

            return(agents);
        }