Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346#include "polymake_fan.h"12Obj REAL_FAN_BY_CONES_SAVE( Polymake_Data* data, Obj cones ){34if( ! IS_PLIST( cones ) ){5ErrorMayQuit( "not a plain list", 0, 0);6return NULL;7}89int numberofcones = LEN_PLIST( cones );10Obj akt;11Obj elem;12Obj numb;13int numberofrays = 0;14data->main_polymake_session->set_application("fan");1516for(int i=1;i<=numberofcones;i++){17akt = ELM_PLIST( cones, i );18#ifdef MORE_TESTS19if( !IS_PLIST( akt ) ){20ErrorMayQuit( "one cone is not a plain list", 0, 0);21return NULL;22}23#endif24numberofrays += LEN_PLIST( akt );2526}27int dimension = LEN_PLIST( ELM_PLIST( ELM_PLIST( cones, 1 ), 1 ) );28pm::Array< pm::Set <pm::Integer> > incMatr(numberofcones,pm::Set<pm::Integer>());29pm::Integer* ratarray = new pm::Integer[ (numberofrays+1)*dimension ];30int raycounter = 1;31for(int i = 0; i < dimension; i++ )32ratarray[i] = 0;33for(int i = 1; i <= numberofcones; i++){34akt = ELM_PLIST( cones, i );35for( int j = 1; j <= LEN_PLIST( akt ); j++){36elem = ELM_PLIST( akt, j );37for( int k = 1; k <= LEN_PLIST( elem ); k++){38numb = ELM_PLIST( elem, k );3940#ifdef MORE_TESTS41if( ! IS_INTOBJ( numb ) ){42ErrorMayQuit( "some entries are not integers", 0, 0);43return NULL;44}45#endif4647ratarray[ raycounter*dimension+(k-1) ] = INT_INTOBJ( numb );4849}50(incMatr[i-1]).collect(raycounter);51raycounter++;52}53}54pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>((numberofrays+1),dimension,ratarray);55perlobj q;56CallPolymakeFunction("check_fan",*matr,incMatr) >> q;57data->polymake_objects->insert( object_pair(data->new_polymake_object_number, &q ) );58elem = INTOBJ_INT( data->new_polymake_object_number );59data->new_polymake_object_number++;60return elem;61}62636465Obj REAL_FAN_BY_CONES( Polymake_Data* data, Obj cones ){6667if( ! IS_PLIST( cones ) ){68ErrorMayQuit( "not a plain list", 0, 0);69return NULL;70}7172int numberofcones = LEN_PLIST( cones );73Obj akt;74Obj elem;75Obj numb;76int numberofrays = 0;77data->main_polymake_session->set_application("fan");7879for(int i=1;i<=numberofcones;i++){80akt = ELM_PLIST( cones, i );81#ifdef MORE_TESTS82if( !IS_PLIST( akt ) ){83ErrorMayQuit( "one cone is not a plain list", 0, 0);84return NULL;85}86#endif87numberofrays += LEN_PLIST( akt );8889}9091int dimension = LEN_PLIST( ELM_PLIST( ELM_PLIST( cones, 1 ), 1 ) );92pm::Array< pm::Set<pm::Integer> >* incMatr;93incMatr = new pm::Array< pm::Set<pm::Integer> >(numberofcones,pm::Set<pm::Integer>());94pm::Integer* ratarray;95ratarray = new pm::Integer[ (numberofrays+1)*dimension ];96int raycounter = 1;97for(int i = 0; i < dimension; i++ )98ratarray[i] = 0;99for(int i = 1; i <= numberofcones; i++){100akt = ELM_PLIST( cones, i );101for( int j = 1; j <= LEN_PLIST( akt ); j++){102elem = ELM_PLIST( akt, j );103for( int k = 1; k <= LEN_PLIST( elem ); k++){104numb = ELM_PLIST( elem, k );105106#ifdef MORE_TESTS107if( ! IS_INTOBJ( numb ) ){108delete [] ratarray;109delete incMatr;110ErrorMayQuit( "some entries are not integers", 0, 0);111return NULL;112}113#endif114115ratarray[ raycounter*dimension+(k-1) ] = INT_INTOBJ( numb );116117}118((*incMatr)[i-1]).collect(raycounter);119raycounter++;120}121}122pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>((numberofrays+1),dimension,ratarray);123perlobj* q = new perlobj("PolyhedralFan<Rational>");124q->take("INPUT_RAYS") << *matr;125q->take("INPUT_CONES") << *incMatr;126elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );127POLYMAKEOBJ_SET_PERLOBJ( elem, q);128delete [] ratarray;129delete incMatr;130delete matr;131return elem;132}133134135136Obj REAL_FAN_BY_RAYS_AND_CONES( Polymake_Data* data, Obj rays, Obj cones ){137138if( ! IS_PLIST( cones ) || ! IS_PLIST( rays ) ){139ErrorMayQuit( "not a plain list", 0, 0);140return NULL;141}142143int numberofrays = LEN_PLIST( rays );144Obj akt;145Obj elem;146Obj numb;147data->main_polymake_session->set_application("fan");148int dimension = LEN_PLIST( ELM_PLIST( rays, 1 ) );149pm::Integer* ratarray;150ratarray = new pm::Integer[ numberofrays*dimension ];151for(int i=0;i<numberofrays;i++){152akt = ELM_PLIST( rays, i+1 );153#ifdef MORE_TESTS154if( !IS_PLIST( akt ) || LEN_PLIST( akt ) != dimension ){155delete [] ratarray;156ErrorMayQuit( "one ray is not a plain list", 0, 0);157return NULL;158}159#endif160for(int j = 0; j<dimension; j++){161numb = ELM_PLIST( akt, j+1 );162#ifdef MORE_TESTS163if( ! IS_INTOBJ( numb ) ){164delete [] ratarray;165ErrorMayQuit( "some entries are not integers", 0, 0);166return NULL;167}168#endif169ratarray[(i*dimension)+j] = INT_INTOBJ( numb );170}171}172int numberofcones = LEN_PLIST( cones );173pm::Array< pm::Set<pm::Integer> >* incMatr;174incMatr = new pm::Array< pm::Set<pm::Integer> >(numberofcones,pm::Set<pm::Integer>());175for(int i=0;i<numberofcones;i++){176akt = ELM_PLIST( cones, i+1 );177#ifdef MORE_TESTS178if( !IS_PLIST( akt ) ){179delete [] ratarray;180delete incMatr;181ErrorMayQuit( "one cone is not a plain list", 0, 0);182return NULL;183}184#endif185for(int j = 0; j < LEN_PLIST( akt ) ; j++){186numb = ELM_PLIST( akt, j+1 );187#ifdef MORE_TESTS188if( ! IS_INTOBJ( numb ) ){189delete [] ratarray;190delete incMatr;191ErrorMayQuit( "some entries are not integers", 0, 0);192return NULL;193}194#endif195((*incMatr)[i]).collect( INT_INTOBJ( numb ) - 1 );196}197}198199pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(numberofrays,dimension,ratarray);200perlobj* q = new perlobj("PolyhedralFan<Rational>");201q->take("INPUT_RAYS") << *matr;202q->take("INPUT_CONES") << *incMatr;203elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );204POLYMAKEOBJ_SET_PERLOBJ( elem, q);205delete [] ratarray;206delete matr;207delete incMatr;208return elem;209}210211// TODO: F212Obj REAL_FAN_BY_RAYS_AND_CONES_UNSAVE( Polymake_Data* data, Obj rays, Obj cones ){213214if( ! IS_PLIST( cones ) || ! IS_PLIST( rays ) ){215ErrorMayQuit( "not a plain list", 0, 0);216return NULL;217}218219int numberofrays = LEN_PLIST( rays );220Obj akt;221Obj elem;222Obj numb;223data->main_polymake_session->set_application("fan");224int dimension = LEN_PLIST( ELM_PLIST( rays, 1 ) );225pm::Integer* ratarray;226ratarray = new pm::Integer[ numberofrays*dimension ];227for(int i=0;i<numberofrays;i++){228akt = ELM_PLIST( rays, i+1 );229#ifdef MORE_TESTS230if( !IS_PLIST( akt ) || LEN_PLIST( akt ) != dimension ){231delete [] ratarray;232ErrorMayQuit( "one ray is not a plain list", 0, 0);233return NULL;234}235#endif236for(int j = 0; j<dimension; j++){237numb = ELM_PLIST( akt, j+1 );238#ifdef MORE_TESTS239if( ! IS_INTOBJ( numb ) ){240delete [] ratarray;241ErrorMayQuit( "some entries are not integers", 0, 0);242return NULL;243}244#endif245ratarray[(i*dimension)+j] = INT_INTOBJ( numb );246}247}248int numberofcones = LEN_PLIST( cones );249pm::IncidenceMatrix< >* incMatr;250incMatr = new pm::IncidenceMatrix<>(numberofcones,numberofrays);251for(int i=0;i<numberofcones;i++){252akt = ELM_PLIST( cones, i+1 );253#ifdef MORE_TESTS254if( !IS_PLIST( akt ) ){255delete [] ratarray;256delete incMatr;257ErrorMayQuit( "one cone is not a plain list", 0, 0);258return NULL;259}260#endif261for(int j = 0; j < LEN_PLIST( akt ) ; j++){262numb = ELM_PLIST( akt, j+1 );263#ifdef MORE_TESTS264if( ! IS_INTOBJ( numb ) ){265delete [] ratarray;266delete incMatr;267ErrorMayQuit( "some entries are not integers", 0, 0);268return NULL;269}270#endif271((*incMatr)[i])+= INT_INTOBJ( numb ) - 1;272}273}274275pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(numberofrays,dimension,ratarray);276perlobj* q = new perlobj("PolyhedralFan<Rational>");277q->take("RAYS") << *matr;278q->take("MAXIMAL_CONES") << *incMatr;279elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );280POLYMAKEOBJ_SET_PERLOBJ( elem, q);281delete [] ratarray;282delete matr;283delete incMatr;284return elem;285}286287288289Obj REAL_RAYS_IN_MAXCONES_OF_FAN( Polymake_Data* data, Obj fan ){290291#ifdef MORE_TESTS292if(! IS_POLYMAKE_FAN(fan) ){293ErrorMayQuit(" parameter is not a fan.",0,0);294return NULL;295}296#endif297298perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( fan );299data->main_polymake_session->set_application_of(*coneobj);300pm::IncidenceMatrix<pm::NonSymmetric> matr;301try302{303pm::IncidenceMatrix<pm::NonSymmetric> matr_temp = coneobj->give("MAXIMAL_CONES");304matr = matr_temp;305}306307POLYMAKE_GAP_CATCH308309Obj RETLI = NEW_PLIST( T_PLIST , matr.rows());310UInt matr_rows = matr.rows();311SET_LEN_PLIST( RETLI , matr_rows );312Obj LIZeil;313UInt matr_cols = matr.cols();314for(int i = 0;i<matr.rows();i++){315LIZeil = NEW_PLIST( T_PLIST, matr.cols());316SET_LEN_PLIST( LIZeil , matr_cols );317for(int j = 0;j<matr.cols();j++){318SET_ELM_PLIST(LIZeil,j+1,INTOBJ_INT(matr(i,j)));319}320SET_ELM_PLIST(RETLI,i+1,LIZeil);321CHANGED_BAG(RETLI);322}323return RETLI;324325}326327328329Obj REAL_NORMALFAN_OF_POLYTOPE( Polymake_Data* data, Obj polytope ){330331#ifdef MORE_TESTS332if(! IS_POLYMAKE_POLYTOPE(polytope) ){333ErrorMayQuit(" parameter is not a polytope.",0,0);334return NULL;335}336#endif337338perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( polytope );339data->main_polymake_session->set_application("fan");340perlobj p;341try{342CallPolymakeFunction("normal_fan",*coneobj) >> p;343}344345POLYMAKE_GAP_CATCH346347perlobj* q = new perlobj(p);348//data->polymake_objects->insert( object_pair(data->new_polymake_object_number, &p ) );349Obj elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );350POLYMAKEOBJ_SET_PERLOBJ( elem, q );351return elem;352}353354355Obj REAL_STELLAR_SUBDIVISION( Polymake_Data* data, Obj ray, Obj fan ){356357#ifdef MORE_TESTS358if( (! IS_POLYMAKE_CONE(ray)) || (! IS_POLYMAKE_FAN(fan)) ){359ErrorMayQuit(" parameter is not a fan or a cone.",0,0);360return NULL;361}362#endif363perlobj* rayobject = PERLOBJ_POLYMAKEOBJ( ray );364perlobj* fanobject = PERLOBJ_POLYMAKEOBJ( fan );365data->main_polymake_session->set_application("fan");366perlobj p;367try{368CallPolymakeFunction("stellar_subdivision",*rayobject,*fanobject) >> p;369}370371POLYMAKE_GAP_CATCH372373perlobj* q = new perlobj(p);374Obj elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );375POLYMAKEOBJ_SET_PERLOBJ( elem, q );376return elem;377}378379380Obj REAL_RAYS_OF_FAN( Polymake_Data* data, Obj fan){381382#ifdef MORE_TESTS383if( ( ! IS_POLYMAKE_FAN(fan) ) ){384ErrorMayQuit(" parameter is not a cone or fan.",0,0);385return NULL;386}387#endif388389perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( fan );390data->main_polymake_session->set_application_of(*coneobj);391pm::Matrix<pm::Rational> matr;392try{393pm::Matrix<pm::Rational> matr_temp = coneobj->give("RAYS");394matr = matr_temp;395}396397POLYMAKE_GAP_CATCH398399Obj RETLI = NEW_PLIST( T_PLIST , matr.rows());400UInt matr_rows = matr.rows();401SET_LEN_PLIST( RETLI , matr_rows );402Obj LIZeil;403UInt matr_cols = matr.cols();404polymake::common::primitive( matr );405for(int i = 0;i<matr.rows();i++){406LIZeil = NEW_PLIST( T_PLIST, matr.cols());407SET_LEN_PLIST( LIZeil , matr_cols );408for(int j = 0;j<matr.cols();j++){409SET_ELM_PLIST(LIZeil,j+1,INTOBJ_INT( (matr(i,j)).to_int() ));410}411SET_ELM_PLIST(RETLI,i+1,LIZeil);412CHANGED_BAG(RETLI);413}414return RETLI;415}416417418Obj REAL_F_VECTOR( Polymake_Data* data, Obj fan){419420#ifdef MORE_TESTS421if( ( ! IS_POLYMAKE_FAN(fan) ) ){422ErrorMayQuit(" parameter is not a cone or fan.",0,0);423return NULL;424}425#endif426427perlobj* fanobj = PERLOBJ_POLYMAKEOBJ( fan );428data->main_polymake_session->set_application_of(*fanobj);429pm::Vector<pm::Integer> matr;430try{431pm::Vector<pm::Integer> matr_temp = fanobj->give("F_VECTOR");432matr = matr_temp;433}434435POLYMAKE_GAP_CATCH436437UInt matr_rows = matr.size();438Obj RETLI = NEW_PLIST( T_PLIST , matr.size() );439SET_LEN_PLIST( RETLI , matr_rows );440for(int i = 0;i<matr.size(); i++){441SET_ELM_PLIST(RETLI,i+1,INTOBJ_INT( (matr[i]).to_int() ));442CHANGED_BAG(RETLI);443}444return RETLI;445}446447