source: git/gfanlib/gfanlibtest.cpp @ f5d2647

spielwiese
Last change on this file since f5d2647 was def863, checked in by Frank Seelisch <seelisch@…>, 13 years ago
included Anders Jensens gfan lib git-svn-id: file:///usr/local/Singular/svn/trunk@13558 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include "../gfanlib.h"
2#include <iostream>
3#include <sstream>
4using namespace gfan;
5using namespace std;
6
7/* Compile using:
8 *  g++ test.cpp -L ../gfanlib_zcone.o -L /Users/anders/gfan/cddlib/lib/libcddgmp.a -L /sw/lib/libgmp.a
9 */
10
11
12/*Printing:
13 */
14string toString(gfan::ZMatrix const &m, char *tab=0)
15{
16  stringstream s;
17
18  for(int i=0;i<m.getHeight();i++)
19    {
20      if(tab)s<<tab;
21      for(int j=0;j<m.getWidth();j++)
22        {
23          s<<m[i][j];
24          if(i+1!=m.getHeight() || j+1!=m.getWidth())
25            {
26              s<<",";
27            }
28        }
29      s<<endl;
30    }
31  return s.str();
32}
33
34string toPrintString(gfan::ZMatrix const &m, int fieldWidth, char *tab=0)
35{
36  stringstream s;
37
38  for(int i=0;i<m.getHeight();i++)
39    {
40      if(tab)s<<tab;
41      for(int j=0;j<m.getWidth();j++)
42        {
43          stringstream temp;
44          temp<<m[i][j];
45          string temp2=temp.str();
46          for(int k=temp2.size();k<fieldWidth;k++)s<<" ";
47          s<<temp2; 
48          if(i+1!=m.getHeight() || j+1!=m.getWidth())
49            {
50              s<<" ";
51            }
52        }
53      s<<endl;
54    }
55  return s.str();
56}
57
58string toString(gfan::ZCone const &c)
59{
60  stringstream s;
61  ZMatrix i=c.getInequalities();
62  ZMatrix e=c.getEquations();
63  s<<"AMBIENT_DIM"<<endl;
64  s<<c.ambientDimension()<<endl;
65  s<<"INEQUALITIES"<<endl;
66  s<<toString(i);
67  s<<"EQUATIONS"<<endl;
68  s<<toString(e);
69  return s.str();
70}
71
72string toPrintString(gfan::ZCone const &c, char *nameOfCone)
73{
74  stringstream s;
75  ZMatrix i=c.getInequalities();
76  ZMatrix e=c.getEquations();
77  s<<nameOfCone<<"[1]:"<<endl;
78  s<<c.ambientDimension()<<endl;
79  s<<nameOfCone<<"[2]:"<<endl;
80  s<<toPrintString(i,6,"   ");
81  s<<nameOfCone<<"[3]:"<<endl;
82  s<<toPrintString(e,6,"   ");
83  return s.str();
84}
85
86
87/* set ok to true before calling the method */
88int integerToInt(gfan::Integer const &V, bool &ok)
89{
90  mpz_t v;
91  mpz_init(v);
92  V.setGmp(v);
93  int ret=0;
94  if(mpz_fits_sint_p(v))
95    ret=mpz_get_si(v);
96  else
97    ok=false;
98  mpz_clear(v);
99  return ret;
100}
101
102
103
104/*
105
106SKETCH:
107-------
108
109intmat zMatrixToIntmat(gfan::ZMatrix const &m)
110{
111  bool ok=true;
112
113  int d=m.getHeight();
114  int n=m.getWidth();
115
116  intmat ret=.....;
117
118  for(int i=0;i<d;i++)
119    for(int j=0;j<n;j++)
120      ret[i][j]=integerToInt(m[i][j],ok);
121
122
123  if(!ok)
124    {
125      ERROR;
126    }
127
128  return ret;
129}
130*/
131
132 /*
133SKETCH:
134-------
135
136ZMatrix intmatToZMatrix(intmat m)
137{
138  int d=;
139  int n=;
140  ZMatrix ret(d,n);
141
142  for(int i=0;i<d;i++)
143    for(int j=0;j<n;j++)
144      ret[i][j]=m[i][j];
145
146  return ret;
147}
148 */
149
150
151
152  /*
153SKETCH:
154-------
155
156intmat zVectorToIntvec(gfan::ZVector const &v)
157{
158  bool ok=true;
159
160  int n=v.size();
161
162  intmat ret=.....;
163
164  for(int i=0;i<n;i++)
165    ret[i]=integerToInt(v[i],ok);
166
167
168  if(!ok)
169    {
170      ERROR;
171    }
172
173  return ret;
174}
175  */
176
177
178
179   /*
180
181SKETCH:
182-------
183
184ZVector intvecToZVector(intvec v)
185{
186  int n=;
187  ZVector ret(n);
188
189  for(int i=0;i<n;i++)
190      ret[i]=m[i];
191
192  return ret;
193}
194   */
195
196
197int main()
198{
199  ZMatrix A(3,2);
200
201  A[0][0]=2;A[0][1]=2;
202  A[1][0]=1;A[1][1]=2;
203  A[2][0]=-2;A[2][1]=1;
204
205  ZMatrix temp(0,2);
206  ZCone C(A,temp);
207
208  cout<<C;
209  C.canonicalize();
210  cout<<C;
211
212  cout<<"Relative interior point"<<endl<<C.getRelativeInteriorPoint()<<endl;
213  cout<<"Extreme rays"<<endl<<C.extremeRays()<<endl;
214  cout<<"Dual cone"<<endl<<C.dualCone()<<endl;
215  cout<<"Unique point"<<endl<<C.getUniquePoint()<<endl;
216  cout<<"Inequalities"<<endl<<C.getInequalities()<<endl;
217
218
219  ZMatrix B(1,2);
220
221  B[0][0]=1;B[0][1]=5;
222  ZCone C2(B,temp);
223  C2.canonicalize();
224  cout<<""<<"Quotient lattice basis"<<endl<<C2.quotientLatticeBasis()<<endl;
225  cout<<""<<"Semigroup generator"<<endl<<C2.semiGroupGeneratorOfRay()<<endl;
226
227
228
229
230
231  std::cerr<<toString(C);
232    std::cerr<<toPrintString(C,"_");
233
234  return 0;
235}
Note: See TracBrowser for help on using the repository browser.