Giter Club home page Giter Club logo

Comments (6)

frrad avatar frrad commented on July 28, 2024

This seems like a bug to me too.

from gophersat.

fdelorme avatar fdelorme commented on July 28, 2024

This is definitely a bug, and I'll have a look at it right now. Sorry for the delay, I haven't been notified of this issue by e-mail.

from gophersat.

gopricy avatar gopricy commented on July 28, 2024

Hi there, thanks for the reply and fix.
I found another failure case after this fix. So the issue should probably be rephrased to “Equal PB Problems can lead to different num of results”.

Here is the failure case

package main

import (
	"fmt"
	"github.com/crillab/gophersat/solver"
)

func main() {
	pb1 := solver.AtMost([]int{1, 2, 3, 4}, 3)
	pb2 := solver.AtLeast([]int{1, 2, 3, 4}, 2)

	case1 := func(){
		pb3 := solver.GtEq([]int{2, 3, 4}, []int{1, 1, 2}, 3)
		pb := solver.ParsePBConstrs([]solver.PBConstr{pb1, pb2, pb3})
		s := solver.New(pb)
		fmt.Println("Case1", s.CountModels())
	}

	case2 := func(){
		pb3 := solver.GtEq([]int{1, 2, 4}, []int{1, 2, 1}, 3)
		pb := solver.ParsePBConstrs([]solver.PBConstr{pb1, pb2, pb3})
		s := solver.New(pb)
		fmt.Println("Case2", s.CountModels())
	}

	case1()
	case2()
}

// output:
// 4
// 5

You can test it out here:
https://play.golang.org/p/lKZ9IlfehRw

@fdelorme can we reopen this issue?

from gophersat.

fdelorme avatar fdelorme commented on July 28, 2024

Yes ! I'll have a look at that.

from gophersat.

fdelorme avatar fdelorme commented on July 28, 2024

The bug is fixed now in the version 1.2.0. It wasn't an issue with PB constraints, but a bug in the solver.CountModels functions, caused by an optimization in the core solver.

For instance, as soon as the solver finds the instance is satisfied by binding the variable x1 to false, and the variables x2 and x4 to false, the solver returns as it doesn't have to try to bind the variable x3 (both x3 and not(x3) satisfy the problem). The problem is, CountModels counted this as a single model (not(x1) and x2 and x4) instead of 2 (not(x1) and x2 and x3 and x4, or not (x1) and x2 and not(x3) and x4).

As of now the fix doesn't appear in the go playground (probably a caching issue), but I tested it locally and it does now display 5 and 5.

Please let me know if you want me to close the issue.

from gophersat.

gopricy avatar gopricy commented on July 28, 2024

@fdelorme Thanks for the explanation and it really makes sense. This new release works for me now! I am closing this ticket now.

from gophersat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.