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

  • Home
  • SEARCH
  • 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 7179177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:05:16+00:00 2026-05-28T17:05:16+00:00

I have the following example code for the knapsack problem in a file called

  • 0

I have the following example code for the knapsack problem in a file called “knapsack.smt2”, which I believe is in smt2 format and I have the latest version of Z3:

(declare-const s1 Int)
(declare-const o1 Int)
(declare-const b1 Bool)

(declare-const s2 Int)
(declare-const o2 Int)
(declare-const b2 Bool)

(declare-const s3 Int)
(declare-const o3 Int)
(declare-const b3 Bool)


(declare-const sack-size Int)
(declare-const filled Int)

(assert (< o1 sack-size))
(assert (< o2 sack-size))
(assert (< o3 sack-size))

(assert (>= o1 0))
(assert (>= o2 0))
(assert (>= o3 0))

(assert (=> (not b1)(= o1 o2)))
(assert (=> (not b2)(= o2 o3)))

(assert (=> b1 (= (+ o1 s1) o2)))
(assert (=> b2 (= (+ o2 s2) o3)))
(assert (=> b3 (= (+ o3 s3) filled)))

(assert (=> (not b3) (= o3 filled)))
(assert (<= filled sack-size))

(assert ( = o1 0))


(assert ( = s1 3))
(assert ( = s2 4))
(assert ( = s3 5))
(assert ( = sack-size 20))

(assert ( = filled 13))

(check-sat)
(get-model)

However, when I run “z3 -m knapsack.smt2” I get the following error message:

>> z3 -m knapsack.smt2
unsat
(error "line 46 column 10: model is not available")

where line 46 is the last line “(get-model)”.

Can anyone tell me why this isn’t working?

Thanks.

  • 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-28T17:05:17+00:00Added an answer on May 28, 2026 at 5:05 pm

    Z3 produces models for satisfiable instances.
    Your formula is not satisfiable. Using the constraints

    (assert ( = o1 0))
    (assert ( = s1 3))
    (assert ( = s2 4))
    (assert ( = s3 5))
    (assert ( = filled 13))
    

    we have that o1 = 0 and s1 = 3, s2 = 3, s3 = 5, and filled = 13,
    Using the constraints

    (assert (=> (not b1)(= o1 o2)))
    (assert (=> b1 (= (+ o1 s1) o2)))
    

    We have that o2 = 0 or o2 = 3.

    Using

    (assert (=> (not b2)(= o2 o3)))
    (assert (=> b2 (= (+ o2 s2) o3)))
    

    We have that o3 = o2 or o3 = o2 + 3
    Using

    (assert (=> b3 (= (+ o3 s3) filled)))
    (assert (=> (not b3) (= o3 filled)))
    

    We have that o3 = 8 or o3 = 13

    Now, we can see the conflict

    o2 = 0 or o2 = 3
    o3 = 8 or o3 = 13
    o3 = o2 or o3 = o2 + 3 
    

    If we try o2 = 0 we get the unsatisfiable formulas

    o3 = 8 or o3 = 13
    o3 = 0 or o3 = 3 
    

    If we try o2 = 3 we get the unsatisfiable formulas

    o3 = 8 or o3 = 13
    o3 = 3 or o3 = 6 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code example (see below). My problem is that the tooltip
I have the following example code, which should pop up an alert when the
My problem can be illustrated in the following example code, which sets up a
I have the following code example for Visual C++ which creates an ActiveX object
I have a problem with the following example code that shows inconsistent behavior for
I have stumbled to following code example: $image = 'file/path'; $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
I have the following example code: class A(object): def __init__(self, id): self.myid = id
Say suppose I have the following Java code. public class Example { public static
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
On a report I have the following code for a field: =Sum([PartQty]*[ModuleQty]) Example results

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.