File: minkowskisum.cpp

package info (click to toggle)
gfan 0.3dfsg-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 2,012 kB
  • ctags: 1,935
  • sloc: cpp: 17,728; makefile: 251
file content (73 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "minkowskisum.h"
#include "printer.h"
#include "parser.h"

#define MINKOWSKIFILEINPUT "minkowski.input"
#define MINKOWSKIFILEOUTPUT "minkowski.output"
#define MINKOWSKIPROGRAM "~/math/software/minkowski/TOPCOM-0.13.2/weibel/essai"

static IntegerVector const& index(IntegerVectorList const &l, int index)
{
  for(IntegerVectorList::const_iterator i=l.begin();i!=l.end();i++)
    {
      if(index==0)return *i;
      index--;
    }
  assert(0);
  return *l.end();
}

IntegerVectorList minkowski(IntegerVectorListList const &polytopes, IntegerVectorListList *sums)
{
  if(sums)*sums=IntegerVectorListList();

  IntegerVectorList ret;
  {
    FILE *f=fopen(MINKOWSKIFILEINPUT,"w");
    
    assert(f);
    {
      fprintf(f,"%i",polytopes.size());
      TopcomPrinter p(f);
      //AsciiPrinter p(f);
      
      for(IntegerVectorListList::const_iterator i=polytopes.begin();i!=polytopes.end();i++)
	p.printVectorList(*i);
    }
    fclose(f);
  }
  system(MINKOWSKIPROGRAM" -v <" MINKOWSKIFILEINPUT " >" MINKOWSKIFILEOUTPUT);

  {
    FILE *f=fopen(MINKOWSKIFILEOUTPUT,"r");
    assert(f);


    {
      FileParser p(f);
      while(p.nextNonBlankDoNotGet())
	{
	  IntegerVector indices=p.parseIntegerVector();
	  if(sums)
	    {
	      IntegerVectorList sum;
	      int i=0;
	      for(IntegerVectorListList::const_iterator I=polytopes.begin();I!=polytopes.end();I++)
		{
		  sum.push_back(index(*I,indices[i]-1));
		  i++;
		}

	      sums->push_back(sum);
	    }
	  int c=p.nextNonBlank();
	  assert(c==':');
	  ret.push_back(p.parseIntegerVector());
	  c=p.nextNonBlank();
	  while(c!=']')c=p.nextNonBlank();
	}
    }
    fclose(f);
  }
  return ret;
}