File: app_mixedvolume.cpp

package info (click to toggle)
gfan 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,372 kB
  • sloc: cpp: 53,144; makefile: 556
file content (103 lines) | stat: -rw-r--r-- 3,350 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include "parser.h"
#include "printer.h"
#include "polynomial.h"
#include "matrix.h"
#include "gfanlib_matrix.h"
//#include "mixedvolume.h"
#include "gfanapplication.h"
#include "gfanlib_mixedvolume.h"
#include "log.h"

using namespace gfan;
using namespace gfan::MixedVolumeExamples;

class MixedVolumeApplication : public GFanApplication
{
	SimpleOption optionVectorInput;
	IntegerOption optionCyclic;
	IntegerOption optionNoon;
	IntegerOption optionChandra;
	IntegerOption optionKatsura;
	IntegerOption optionGaukwa;
	IntegerOption optionEco;
	IntegerOption optionNThreads;
	IntegerOption optionSteps;
public:
  const char *helpText()
  {
    return "This program computes the mixed volume of the Newton polytopes of a list of polynomials. The ring is specified on the input. After this follows the list of polynomials.\n";
  }
  MixedVolumeApplication():
	  optionVectorInput("--vectorinput","Read in a list of point configurations instead of a polynomial ring and a list of polynomials."),
	  optionCyclic("--cyclic","Use cyclic-n example instead of reading input."),
	  optionNoon("--noon","Use Noonburg-n example instead of reading input."),
	  optionChandra("--chandra","Use Chandrasekhar-n example instead of reading input."),
	  optionKatsura("--katsura","Use Katsura-n example instead of reading input."),/* Note that Verschelde's mixed volumes for the Katsura examples do not match those produced by gfan. The configurations do not seem to be identical for all n. */
	  optionGaukwa("--gaukwa","Use Gaukwa-n example instead of reading input."),
	  optionEco("--eco","Use Eco-n example instead of reading input."),
	  optionNThreads("-j","Number of threads"),
	  optionSteps("-s","Number of steps", 500)
  {
	  optionSteps.hide();
	  registerOptions();
  }
  const char *name()
  {
    return "_mixedvolume";
  }
  IntMatrix rowsToIntegerMatrix(IntegerVectorList const &l)
  {
	  assert(l.size());
	  IntMatrix ret(l.size(),l.front().size());
	  IntegerVectorList::const_iterator I=l.begin();
	  for(int i=0;i<ret.getHeight();i++,I++)
		  for(int j=0;j<ret.getWidth();j++)
			  ret[i][j]=(*I)[j];
	  return ret;
  }
  int main()
  {
		int nthreads=optionNThreads.getValue();
		int steps=optionSteps.getValue();
		vector<IntMatrix> tuple;

		if(optionCyclic.getValue())
			tuple=cyclic(optionCyclic.getValue());
		else if(optionNoon.getValue())
			tuple=noon(optionNoon.getValue());
		else if(optionChandra.getValue())
			tuple=chandra(optionChandra.getValue());
		else if(optionKatsura.getValue())
			tuple=katsura(optionKatsura.getValue());
		else if(optionGaukwa.getValue())
			tuple=gaukwa(optionGaukwa.getValue());
		else if(optionEco.getValue())
			tuple=eco(optionEco.getValue());
		else
		{
			IntegerVectorListList tuple1;
			if(optionVectorInput.getValue())
			{
				tuple1=FileParser(Stdin).parseIntegerVectorListList();
			}
			else
			{
				PolynomialSet g=FileParser(Stdin).parsePolynomialSetWithRing();

				tuple1=g.exponents();
			}
			for(IntegerVectorListList::const_iterator i=tuple1.begin();i!=tuple1.end();i++)
				tuple.push_back(rowsToIntegerMatrix(*i).transposed());
		}

		log1 for(auto i=tuple.begin();i!=tuple.end();i++)std::cerr<<*i;

		cout<<mixedVolume(tuple,nthreads,steps)<<"\n";
		//    cout << mixedVolume(s) << endl;

		return 0;
  }
};

static MixedVolumeApplication theApplication;