exec

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package exec implements addition chain algorithm execution.

Example
package main

import (
	"fmt"
	"log"
	"math/big"

	"github.com/mmcloughlin/addchain/alg/ensemble"
	"github.com/mmcloughlin/addchain/alg/exec"
)

func main() {
	// Target number: 2²⁵⁵ - 21.
	n := new(big.Int)
	n.SetString("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeb", 16)

	// Default ensemble of algorithms.
	algorithms := ensemble.Ensemble()

	// Use parallel executor.
	ex := exec.NewParallel()
	results := ex.Execute(n, algorithms)

	// Output best result.
	best := 0
	for i, r := range results {
		if r.Err != nil {
			log.Fatal(r.Err)
		}
		if len(results[i].Program) < len(results[best].Program) {
			best = i
		}
	}
	r := results[best]
	fmt.Printf("best: %d\n", len(r.Program))
	fmt.Printf("algorithm: %s\n", r.Algorithm)

}
Output:

best: 266
algorithm: opt(runs(continued_fractions(dichotomic)))

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parallel

type Parallel struct {
	// contains filtered or unexported fields
}

Parallel executes multiple algorithms in parallel.

func NewParallel

func NewParallel() *Parallel

NewParallel builds a new parallel executor.

func (Parallel) Execute

func (p Parallel) Execute(n *big.Int, as []alg.ChainAlgorithm) []Result

Execute all algorithms against the provided target.

func (*Parallel) SetConcurrency

func (p *Parallel) SetConcurrency(limit int)

SetConcurrency sets the number of algorithms that may be run in parallel.

func (*Parallel) SetLogger

func (p *Parallel) SetLogger(l *log.Logger)

SetLogger sets logging output.

type Result

type Result struct {
	Target    *big.Int
	Algorithm alg.ChainAlgorithm
	Err       error
	Chain     addchain.Chain
	Program   addchain.Program
}

Result from applying an algorithm to a target.

func Execute

func Execute(n *big.Int, a alg.ChainAlgorithm) Result

Execute the algorithm on the target number n.

Jump to

Keyboard shortcuts

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