Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1066177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:58:39+00:00 2026-05-16T19:58:39+00:00

I have many variable-sized lists containing instances of the same class with attribute foo,

  • 0

I have many variable-sized lists containing instances of the same class with attribute foo, and for every list I must apply rules like:

  • if there’s an element foo=A there cannot be elements with foo in [B,C,D]
  • if there’s an element foo=X there must by at least one with foo in [Y,Z]
  • there can be between MIN and MAX elements foo=BAR

combining the above three rules is probably enough to express any similar constraint I’ll ever need. It’s something like dependency checking in software packages but I have quantities and lack versions 🙂

a naïve approach would be:

R_CONFLICT={ A: [B,C,D] }
R_DEPENDS ={ X: [ [Y,Z], W, .. } # means: A depends on either Y or Z, and W
R_MIN     ={BAR: n, BAZ: m}
R_MAX     ={BAR: o, BAZ: p}
# now just loop over lists to check them..

Is this a problem of Constraint programming? I don’t actually need to solve something to get a result, I need to validate my list against some constraints and check if they are satisfied or not. How would you classify this problem and how would you solve it?

For what it’s worth, I’m coding in Python, but I welcome a generic programming answer 🙂 If it turns out I must delve in constraint programming I’ll probably start by trying python-constraint.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:58:40+00:00Added an answer on May 16, 2026 at 7:58 pm

    Short answer – yes this could be checked using constraint programming, in effect you are supplying a solution and checking it against constraints rather than having the solver search through domains of potentials for a matching solution. Which kind of makes constraint programming overkill, especially if you are using Python which can quite easily check those kind of conditions.

    I don’t have Python on this machine so there may be a typo/error in this code but it shows what you’re after without needing to get involved with constraint programming.

    conflict = set([B, C , D])
    foos = set([x.foo for x in list])
    if A in foos:
        if len(foos & conflict): #Set intersection
             return false
    
    len([x for x in list where x.foo == BAR]) #Gives you number of occurances of BAR
    

    Basically I’d say unless the constraints are going to get much more complex or you’re going to want to find solutions rather than just test I’d stick with code rather than constraint programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that I'm using many times in a class and as
I have an initialization class that preloads content into a variable (probably a list
so i have many controllers and many views. i want my variable @random_quote to
I have a js variable with many functions, and I want to create in
I have a question about variable scope in a C++ class. The problem I'm
Suppose I have following template class: template<unsigned char I, unsigned char F> class FOO
I am a beginner and I have a file having variable sized records; there
I have a (C++) system that has many classes that have variable storage (memory)
I have objects with many variables that I declare and explain in the comments.
I have many js methods that uses global variables like: function DoSomething() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.