Beispiel #1
0
    public Frontier CanFulfillConstraints(Frontier frontier)
    {
        // Console.WriteLine("In member {0}", this.name);

        if (CatCatToId.data.ContainsKey(memberOf))
        {
            foreach (var cat in CatCatToId.data[memberOf].Keys)
            {
                var currentId = CatCatToId.data[this.memberOf][cat];
                if (frontier.usedConstraintIds.Contains(currentId))
                {
                    continue;
                }
                if (!to.ContainsKey(cat) || to.Count == 0)
                {
                    // Console.WriteLine("{0} has no {1}!", this.name, cat.symbol);
                    return(null);
                }
                if (frontier.foundPairs.ContainsKey(cat))
                {
                    foreach (var el in to[cat])
                    {
                        // Console.WriteLine("  TRY {0}", el.name);
                        if (el == frontier.foundPairs[cat])
                        {
                            // Console.WriteLine("! TRY {0}", el.name);
                            return(frontier.AddUsedConstraintId(currentId));
                        }
                        // Console.WriteLine("X TRY {0}", el.name);
                    }
                    return(null);
                }
            }
        }

        List <Category> reachable = new List <Category>();

        foreach (var cat in frontier.missingCats)
        {
            if (CatCatToId.data.ContainsKey(memberOf) && CatCatToId.data[memberOf].ContainsKey(cat))
            {
                reachable.Add(cat);
            }
        }
        return(this.CanReachAll(frontier, reachable));
    }
Beispiel #2
0
    private Frontier CanReachAll(Frontier frontier, List <Category> reachable)
    {
        // Console.Write("canReachAll {0}", this.name);
        // reachable.ForEach(r => Console.Write(r.symbol + ", "));
        // Console.WriteLine();
        if (reachable.Count == 0)
        {
            return(frontier);
        }
        var cat           = reachable.First();
        var nextReachable = new List <Category>(reachable);

        nextReachable.Remove(cat);
        var currentId = CatCatToId.data[this.memberOf][cat];

        if (frontier.usedConstraintIds.Contains(currentId))
        {
            return(CanReachAll(frontier, nextReachable));
        }
        if (!to.ContainsKey(cat))
        {
            // Console.WriteLine("{0} has no {1}.", this.name, cat.symbol);
            return(null);
        }

        // Console.WriteLine("adding catcatId {0}", currentId);
        var nextFront = frontier.AddUsedConstraintId(currentId).RemoveMissingCat(cat);

        foreach (var el in to[cat])
        {
            // Console.WriteLine("  try {0} -> {1}", cat.symbol, el.name);
            var nextFront2   = nextFront.AddFoundPairs(cat, el);
            var workingFront = el.CanFulfillConstraints(nextFront2);
            if (workingFront != null)
            {
                // Console.WriteLine("! try {0}", el.name);
                var workingFront2 = CanReachAll(workingFront, nextReachable);
                if (workingFront2 != null)
                {
                    return(workingFront2);
                }
            }
            // Console.WriteLine("X try {0} -> {1}", cat.symbol, el.name);
        }
        return(null);
    }