func NewLibraryGraph() *LibraryGraph {
	return &LibraryGraph{
		libraries:    []uniqueLibrary{},
		dependencies: []dependency{},
		verbose:      false,
	}
}
/*
This function creates a new LibraryGraph object.
package graph
import (
	"fmt"
	"log"
	"github.com/blang/semver"
)
type LibraryName string
type LibraryGraph struct {
	dependencies []dependency
	libraries    []uniqueLibrary
	verbose      bool
}
func (graph LibraryGraph) Exists(d dependency) bool {
	for _, c := range graph.dependencies {
		if c.Equals(d) {
			return true
		}
	}
	return false
}
func (graph *LibraryGraph) Verbose(v bool) {
	graph.verbose = v
}
func (graph LibraryGraph) Contains(lib LibraryName, libver semver.Version) bool {
	for _, l := range graph.libraries {
		if l.Equals(lib, libver) {
			return true
		}
	}
	return false
}
func (graph *LibraryGraph) AddLibrary(lib LibraryName, libver semver.Version) {
	for _, l := range graph.libraries {
		if l.Equals(lib, libver) {
			return
		}
	}
	graph.libraries = append(graph.libraries, uniqueLibrary{name: lib, ver: libver})
}
func (graph *LibraryGraph) AddDependency(lib LibraryName, libver semver.Version,
	deplib LibraryName, depver semver.Version) error {
	lfound := false
	dfound := false
	for _, l := range graph.libraries {
		if l.Equals(lib, libver) {
			lfound = true
		}
		if l.Equals(deplib, depver) {
			dfound = true
		}
	}
	if !lfound {
		return fmt.Errorf("Cannot add dependency for unknown library %s v%s",
			lib, libver.String())
	}
	if !dfound {
		return fmt.Errorf("Cannot add dependency for unknown library %s v%s",
			deplib, depver.String())
	}
	library := uniqueLibrary{name: lib, ver: libver}
	dependsOn := uniqueLibrary{name: deplib, ver: depver}
	dep := dependency{library: library, dependsOn: dependsOn}
	if !graph.Exists(dep) {
		graph.dependencies = append(graph.dependencies, dep)
	}
	return nil
}
func (graph LibraryGraph) Versions(lib LibraryName) *VersionList {
	present := map[string]semver.Version{}
	for _, l := range graph.libraries {
		if l.name == lib {
			present[l.ver.String()] = l.ver
		}
	}
	vl := NewVersionList()
	for _, sv := range present {
		vl.Add(sv)
	}
	vl.ReverseSort()
	return vl
}
func (graph LibraryGraph) Dependencies(lib LibraryName, ver semver.Version) Possible {
	depvers := Possible{}
	for _, dep := range graph.dependencies {
		if dep.library.name == lib && ver.Compare(dep.library.ver) == 0 {
			dver, found := depvers[dep.dependsOn.name]
			if !found {
				dver = NewVersionList()
				depvers[dep.dependsOn.name] = dver
			}
			dver.Add(dep.dependsOn.ver)
		}
	}
	return depvers
}
func (graph LibraryGraph) findFirst(
	mapped Configuration,  
	verbose bool,  
	avail Possible,  
	rest ...LibraryName,  
) (Configuration, error) {
	if verbose {
		log.Printf("Call to findFirst...")
		log.Printf("  Resolved: %v", mapped)
		log.Printf("  Avail: %v", avail)
		log.Printf("  Yet to be Resolved: %v", rest)
	}
	if len(rest) == 0 {
		if verbose {
			log.Printf("End of the line, returning %v", mapped)
		}
		return mapped, nil
	}
	lib := rest[0]
	rest = rest[1:]
	if verbose {
		log.Printf("  -> Library to Resolve: %v", lib)
		log.Printf("  -> Remaining: %v", rest)
	}
	vers := avail[lib]
	if vers == nil {
		log.Printf("Error, unable to find library %s (mapped: %v, rest: %v)",
			lib, mapped, rest)
		return nil, fmt.Errorf("Internal error handling library %s", lib)
	}
	for _, ver := range *vers {
		if verbose {
			log.Printf("  Considering version %v of %s", ver, lib)
		}
		config := mapped.Clone()
		newlibs := []LibraryName{}
		depvers := graph.Dependencies(lib, ver)
		if verbose {
			log.Printf("Dependencies of %s:%s -> %s", lib, ver.String(), depvers)
		}
		for d, vl := range depvers {
			choice, chosen := mapped[d]
			if chosen {
				if !vl.Contains(choice) {
					return nil, fmt.Errorf("No compatible version of %s", d)
				}
			}
		}
		for l, _ := range mapped {
			delete(depvers, l)
		}
		if verbose {
			log.Printf("Dependencies after mapping -> %s", depvers)
		}
		newavail := avail.Clone()
		for n1, v1 := range depvers {
			if n1 == lib {
				if v1.Contains(ver) {
					continue
				} else {
					return nil,
						fmt.Errorf("Inconsistent circular dependency for library %v", lib)
				}
			}
			found := false
			for _, n2 := range rest {
				if n1 == n2 {
					found = true
				}
			}
			if !found {
				newlibs = append(newlibs, n1)
				newavail[n1] = graph.Versions(n1)
			}
		}
		newavail = newavail.Refine(depvers)
		if verbose {
			log.Printf("Intersection between %s and %s -> %s", avail, depvers, newavail)
		}
		delete(newavail, lib)
		if verbose {
			log.Printf("Intersection - %s -> %s", lib, newavail)
		}
		empty := newavail.Empty()
		if len(empty) > 0 {
			return nil, fmt.Errorf("No compatible versions of: %v", empty)
		}
		config[lib] = ver
		newlibs = append(newlibs, rest...)
		sol, err := graph.findFirst(config, verbose, newavail, newlibs...)
		if err == nil {
			return sol, err
		}
	}
	return nil, fmt.Errorf("No compatible versions of %s found", lib)
}
func (graph LibraryGraph) Resolve(libraries ...LibraryName) (config Configuration, err error) {
	ret := Possible{}
	for _, lib := range libraries {
		ret[lib] = graph.Versions(lib)
	}
	return graph.findFirst(config, graph.verbose, ret, libraries...)
}