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 6611791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:58+00:00 2026-05-25T20:00:58+00:00

Me and a friend are writing a program which is supposed to solve a

  • 0

Me and a friend are writing a program which is supposed to solve a CLP problem. We want to use minimize to optimize the solution but it won’t work, because it keeps saying that the number we get from sum(P,#=,S) is between two numbers (for example 5..7). We haven’t been able to find a good way to extract any number from this or manipulate it in any way and are therefore looking for your help.

The problem seems to arise from our gen_var method which says that each element of a list must be between 0 and 1, so some numbers come out as “0..1” instead of being set properly.

Is there any way to use minimize even though we get a number like “5..7” or any way to manipulate that number so that we only get 5? S (the sum of the elements in a list) is what we’re trying to minimize.

gen_var(0, []).
gen_var(N, [X|Xs]) :-
        N > 0,
        M is N-1,
        gen_var(M, Xs),
    domain([X],0,1).

find([],_).
find([H|T],P):- match(H,P),find(T,P).

match(pri(_,L),P):-member(X,L), nth1(X,P,1).

main(N,L,P,S) :- gen_var(N,P), minimize(findsum(L,P,S),S).
findsum(L,P,S):- find(L,P), sum(P,#=,S).
  • 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-25T20:00:59+00:00Added an answer on May 25, 2026 at 8:00 pm

    I’ve slightly modified your code, to adapt to SWI-Prolog CLP(FD), and it seems to work (kind of). But I think the minimum it’s always 0!

    :- use_module(library(clpfd)).
    
    gen_var(0, []).
    gen_var(N, [X|Xs]) :-
        N > 0,
        M is N-1,
        gen_var(M, Xs),
        X in 0..1 .
    
    find([], _).
    find([H|T], P):-
        match(H, P),
        find(T, P).
    
    match(pri(_,L),P):-
        member(X, L),
        nth1(X, P, 1).
    
    findsum(L,P,S) :-
        find(L, P),
        sum(P, #=, S).
    
    main(N, L, P, S) :-
        gen_var(N, P),
        findsum(L, P, S),
        labeling([min(S)], P).
    

    Is this output sample a correct subset of the expected outcome?

    ?- main(3,A,B,C).
    A = [],
    B = [0, 0, 0],
    C = 0 ;
    A = [],
    B = [0, 0, 1],
    C = 1 ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a photo gallery webapp for a friend's wedding and they want a
I'm writing a web application (PHP) for my friend and have decided to use
I had a friend ask me about writing a program that would allow data
I'm writing a silly program in python for a friend that prints We are
I am writing a program in c++ which implements a doubly-linked list that holds
I am currently writing a program that I need to send to a friend
Solution for writing a program for keep secret photos. I have many secret photos
I'm helping out a friend, writing him a program. He is re-recording the soundtrack
I´m writing an program that uses twitter. I want that my app shows an
I'm writing a program using the Winsock API because a friend wanted a simple

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.