integeruser / FP-growth

A C++ implementation of the FP-growth algorithm
MIT License
42 stars 22 forks source link

Running problem with Visual Studio 2017 #5

Closed DJuego closed 6 years ago

DJuego commented 6 years ago

Well. Now I want to run the sample with Visual Studio 2017 (15.6.2) in "Debug" mode. Do not work.

I isolated the problem:

When i run:

int main()
{
    // order items by decreasing frequency
    std::map<Item, uint64_t> frequency_by_item;

    frequency_by_item["A"] = 5;
    frequency_by_item["B"] = 6;

    struct decreasing_order_comparator {
        bool operator() (const std::pair<uint64_t, Item>& lhs, const std::pair<uint64_t, Item>& rhs) const
        {
            return (lhs.first > rhs.first) or (not (lhs.first > rhs.first) and lhs.second < rhs.second);
        }
    };
    std::set<std::pair<uint64_t, Item>, decreasing_order_comparator> items_ordered_by_frequency;
    for (const auto& pair : frequency_by_item) {
        const Item& item = pair.first;
        const uint64_t frequency = pair.second;
        items_ordered_by_frequency.insert({ frequency, item });
    }
}

I get: " Debug Assertion Failed! Program: C:\Windows\SYSTEM32\MSVCP140D.dll File: c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.13.26128\include\xtree Line: 1744 Expression: invalid comparator "

On the other hand, when i run the code In release mode the tests fail: For example: test 1: 19 patterns are expected. 13 are obtained.

My bad. The tests failed because i had modified the comparison. Sorry.

return (lhs.first > rhs.first) or (not (lhs.first > rhs.first) and lhs.second < rhs.second);

to

 return (lhs.first > rhs.first) /*or (not(lhs.first > rhs.first) and lhs.second < rhs.second)*/;

The assert problem seems related with: lhs.second < rhs.second

Sorry again.

Yes. In release mode it seems that the tests are successfully passed (assert does not work in release mode).

DJuego

DJuego commented 6 years ago

Resolved! 😃 I have found the solution in Stack Overflow

It is proposed the next modification:

 struct decreasing_order_comparator {
        bool operator() (const std::pair<uint64_t, Item>& lhs, const std::pair<uint64_t, Item>& rhs) const
        {
            return (lhs.first > rhs.first) or (not(lhs.first > rhs.first) and lhs.second < rhs.second);
            }
}:

to:

 struct decreasing_order_comparator {
        bool operator() (const std::pair<uint64_t, Item>& lhs, const std::pair<uint64_t, Item>& rhs) const
        {           
            return std::tie(lhs) < std::tie(rhs);
            }
};

Another alternative:

 struct decreasing_order_comparator {
        bool operator() (const std::pair<uint64_t, Item>& lhs, const std::pair<uint64_t, Item>& rhs) const
        {           
            if (lhs.first != rhs.first)
            {
                return (lhs.first > rhs.first);
            }
            return (lhs.second < rhs.second);
            }
};

@integeruser , I suggest you study this fix, and if it seems right, make the change. The official tests are successfully passed in Visual Studio 2017 and gcc 7.3.0 (MinGW).

With this change, your FP-growth implementation would achieve compatibility with Visual Studio 2017 (at least).

DJuego

integeruser commented 6 years ago

Again, thanks for reporting and investigating, this should be fixed now. Feel free to reopen the issue if something's still wrong.