Skip to content

Commit

Permalink
fixed AvailabilityTest and added ExternalConditions
Browse files Browse the repository at this point in the history
* avoid using IO_FindExecutable in AvailabilityTest as suggested by @alex-konovalov in
#329 (comment)
* added ExternalConditions as suggested by @alex-konovalov in
#189 (comment)

Closes #189 and closes #329.
  • Loading branch information
mohamed-barakat committed May 5, 2020
1 parent 2ffa65a commit 0d9f2e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 74 deletions.
10 changes: 4 additions & 6 deletions 4ti2Interface/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Version := Maximum( [
## this line prevents merge conflicts
"2018.07.06", ## Kamal's version
## this line prevents merge conflicts
"2020.05.04", ## Mohamed's version
"2020.05.05", ## Mohamed's version
] ),

Date := ~.Version{[ 1 .. 10 ]},
Expand Down Expand Up @@ -66,9 +66,7 @@ Dependencies := rec(
GAP := ">=4.7",
NeededOtherPackages := [ [ "io", ">=4.2" ] ],
SuggestedOtherPackages := [ [ "AutoDoc", ">=2013.08.22" ] ],
OtherPackagesLoadedInAdvance := [ [ "io", ">=4.2" ] ],
ExternalConditions := []

ExternalConditions := [ [ "4ti2", "https://4ti2.github.io/" ] ],
),

AvailabilityTest := function()
Expand All @@ -82,8 +80,8 @@ AvailabilityTest := function()
bool :=
ForAll( 4ti2_binaries,
name ->
( not ValueGlobal( "IO_FindExecutable" )( name ) = fail ) or
( not ValueGlobal( "IO_FindExecutable" )( Concatenation( "4ti2-", name ) ) = fail ) );
( not Filename(DirectoriesSystemPrograms(), name ) = fail ) or
( not Filename(DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) ) = fail ) );

if not bool then
LogPackageLoadingMessage( PACKAGE_WARNING,
Expand Down
1 change: 1 addition & 0 deletions 4ti2Interface/gap/4ti2Interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#! Copy it in your GAP pkg-directory.
#! After this, the package can be loaded via LoadPackage( "4ti2Interface" );

DeclareGlobalVariable( "4ti2Interface_BINARIES" );

#! @Chapter 4ti2 functions

Expand Down
102 changes: 34 additions & 68 deletions 4ti2Interface/gap/4ti2Interface.gi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
##
#############################################################################

InstallValue( 4ti2Interface_BINARIES,
rec(
required_binaries := [ "groebner", "hilbert", "zsolve", "graver" ],
) );

for name in 4ti2Interface_BINARIES.required_binaries do
path := Filename( DirectoriesSystemPrograms(), name );
if IsStringRep( path ) then
4ti2Interface_BINARIES.(name) := path;
continue;
fi;
path := Filename( DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) );
if IsStringRep( path ) then
4ti2Interface_BINARIES.(name) := path;
continue;
fi;
## the AvailabilityTest in the PackageInfo will prevent this error from being raised
Error( "4ti2 cannot be found on your system\n" );
od;

##
InstallGlobalFunction( 4ti2Interface_Cut_Vector,

Expand Down Expand Up @@ -171,14 +191,8 @@ InstallGlobalFunction( 4ti2Interface_groebner,
4ti2Interface_Write_Matrix_To_File( arg[ 2 ], Concatenation( filename, ".cost" ) );

fi;

if IO_FindExecutable( "groebner" ) <> fail then
exec := IO_FindExecutable( "groebner" );
elif IO_FindExecutable( "4ti2-groebner" ) <> fail then
exec := IO_FindExecutable( "4ti2-groebner" );
else
Error( "4ti2 can not be found" );
fi;

exec := 4ti2Interface_BINARIES.groebner;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -247,14 +261,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities,
sign_list := [ List( matrix[ 1 ], i -> 0 ) ];

4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );

if IO_FindExecutable( "hilbert" ) <> fail then
exec := IO_FindExecutable( "hilbert" );
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
exec := IO_FindExecutable( "4ti2-hilbert" );
else
Error( "4ti2 can not be found" );
fi;

exec := 4ti2Interface_BINARIES.hilbert;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -303,15 +311,9 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities_in_positive_orthant,
rel_list := [ List( matrix, i -> ">" ) ];

4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) );

if IO_FindExecutable( "hilbert" ) <> fail then
exec := IO_FindExecutable( "hilbert" );
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
exec := IO_FindExecutable( "4ti2-hilbert" );
else
Error( "4ti2 can not be found" );
fi;

exec := 4ti2Interface_BINARIES.hilbert;

precision := ValueOption( "precision" );

if IsInt( precision ) then
Expand Down Expand Up @@ -360,13 +362,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_in_positive_orthant,

4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) );

if IO_FindExecutable( "hilbert" ) <> fail then
exec := IO_FindExecutable( "hilbert" );
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
exec := IO_FindExecutable( "4ti2-hilbert" );
else
Error( "4ti2 can not be found" );
fi;
exec := 4ti2Interface_BINARIES.hilbert;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -422,14 +418,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities,
sign_list := [ List( concat_list[ 1 ] , i -> 0 ) ];

4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );

if IO_FindExecutable( "hilbert" ) <> fail then
exec := IO_FindExecutable( "hilbert" );
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
exec := IO_FindExecutable( "4ti2-hilbert" );
else
Error( "4ti2 can not be found" );
fi;

exec := 4ti2Interface_BINARIES.hilbert;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -486,13 +476,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities_in_posi

4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );

if IO_FindExecutable( "hilbert" ) <> fail then
exec := IO_FindExecutable( "hilbert" );
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
exec := IO_FindExecutable( "4ti2-hilbert" );
else
Error( "4ti2 can not be found" );
fi;
exec := 4ti2Interface_BINARIES.hilbert;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -585,14 +569,8 @@ InstallGlobalFunction( 4ti2Interface_zsolve_equalities_and_inequalities,
concat_rhs := [ Concatenation( eqs_rhs, ineqs_rhs ) ];

4ti2Interface_Write_Matrix_To_File( concat_rhs, Concatenation( filename, ".rhs" ) );

if IO_FindExecutable( "zsolve" ) <> fail then
exec := IO_FindExecutable( "zsolve" );
elif IO_FindExecutable( "4ti2-zsolve" ) <> fail then
exec := IO_FindExecutable( "4ti2-zsolve" );
else
Error( "4ti2 can not be found" );
fi;

exec := 4ti2Interface_BINARIES.zsolve;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -708,13 +686,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities,

4ti2Interface_Write_Matrix_To_File( signs, Concatenation( filename, ".sign" ) );

if IO_FindExecutable( "graver" ) <> fail then
exec := IO_FindExecutable( "graver" );
elif IO_FindExecutable( "4ti2-graver" ) <> fail then
exec := IO_FindExecutable( "4ti2-graver" );
else
Error( "4ti2 can not be found" );
fi;
exec := 4ti2Interface_BINARIES.graver;

precision := ValueOption( "precision" );

Expand Down Expand Up @@ -755,13 +727,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities_in_positive_orthant,

4ti2Interface_Write_Matrix_To_File( eqs, Concatenation( filename, ".mat" ) );

if IO_FindExecutable( "graver" ) <> fail then
exec := IO_FindExecutable( "graver" );
elif IO_FindExecutable( "4ti2-graver" ) <> fail then
exec := IO_FindExecutable( "4ti2-graver" );
else
Error( "4ti2 can not be found" );
fi;
exec := 4ti2Interface_BINARIES.graver;

precision := ValueOption( "precision" );

Expand Down

0 comments on commit 0d9f2e7

Please sign in to comment.