gen

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gen contains generators for common kinds of formulas.

Package gen also supplies a random solver, which returns random results within a random period of time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinCycle

func BinCycle(dst inter.Adder, n int)

BinCycle generates (1,-2) (2,-3), (3,-4) ... (n-1, -(n)), (n, 1)

func HardRand3Cnf

func HardRand3Cnf(dst inter.Adder, n int)

HardRand3Cnf generates a random 3cnf with n variables.

func PartVar

func PartVar(i, k, n int) z.Lit

PartVar returns a variable if element i is in partition k for a set of n elements.

func Partition

func Partition(dst inter.Adder, n, k int)

Partition adds constraints to dst stating that there exists a partition of n elements into k parts. Every model of the result is a partition with PartVar(i, k, n) true if and only if element i is in partition k.

func Php

func Php(dst inter.Adder, P, H int)

Php generates a pigeon hole problem asking whether or not P pigeons can be placed in H holes with 1 pigeon per hole.

func Py2Triples

func Py2Triples(dst inter.Adder, n int)

Py2Triples adds constraints to dst stating that there is a 2-partition of [1..n] such that no triple (a,b,c) appears in one partition with a^2 + b^2 = c^2.

func PyTriples

func PyTriples(dst inter.Adder, n, k int)

PyTriples adds constraints stating there is no triple (i,j,k) s.t i^2 + j^2 = k^2 in some partition of a k-partition of [1..n]

func Rand3Cnf

func Rand3Cnf(dst inter.Adder, n, m int)

Rand3Cnf generates a random 3cnf with n variables and m clauses.

func RandColor

func RandColor(dst inter.Adder, n, m, k int)

RandColor creates a formula asking if a random (simple) graph with n nodes and m edges can be colored with k colors. Every node must have a color and no 2 adjacent nodes may have the same color.

func RandGraph

func RandGraph(n, m int) [][]int

RandGraph creates a simple (undirected) random graph with n nodes and m edges. If m > n*(n-1)/2, RandGraph returns nil.

The result is in the form of an edge list, namely each node is idenitified by an integer in [0..n) and the edgelist for node i is result[i], which is a list of edges. There are no multi-edges, no self edges, and sampling is done without replacement. The number m is is the number of edges (a, b) such that a < b, the symmetric view of the graph is returned with 2*m edges symmetrified.

func RandS

func RandS(d time.Duration, res int) inter.S

RandS creates an inter.S which just returns result to Solve() within a random period of time chosen from [0..d). The result may be specified ahead of time, however if the result is 0, then a random value from {-1,1} is chosen.

GoSolve() works as usual.

other inter.S methods are just stubs with default values.

This is useful for testing applications using inter.S

func RandSr

func RandSr(d time.Duration, res int, src rand.Source) inter.S

func Seed

func Seed(s int64)

Types

type RandCuber

type RandCuber interface {
	RandCube(dst []z.Lit) []z.Lit
}

func NewRandCuber

func NewRandCuber(maxSize int, maxVar z.Var) RandCuber

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL