/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*/

#include <Poly.h>
#include <t_graph.h>
#include <argv_options.h>

namespace polymake {
namespace topaz {

namespace {
   enum { weighted };
}

void t_mixed_graph(Poly& p, const argv_option *options)
{
   const Array< Set<int> > C = p.give("FACETS");
   const Graph<> PG = p.give("GRAPH");
   const Graph<> DG = p.give("DUAL_GRAPH");
   const int dim = p.give("DIM");
   
   // default for weight = sqrt((dim+1)/(12*Pi))
   // approximation for the radius of the embedding-sphere of a springembedded d-simplex
   const double weight = options[weighted] ? atof(options[weighted]) * sqrt(dim+1) / 6.14 : sqrt(dim+1) / 6.14;
   
   //   Graph<nothing,double> MG=t_mixed_graph(C,PG,DG,weight);
   //   cerr << "MIXED_GRAPH\n" << MG << endl;
   p.take("MIXED_GRAPH") << std::setprecision(6) << t_mixed_graph(C,PG,DG,weight);
}
   
} }

using namespace polymake;

/** @file t_mixed_graph
 *
 *  Produces the mixed graph of a simplicial complex.
 *
 *
 *  @synopsis t_mixed_graph <file> [ -weighted <mixed_edge_weight> ]
 *
 *  @reading  FACETS, GRAPH, DUAL_GRAPH, DIM
 *  @writing  MIXED_GRAPH
 */

int main(int argc, const char* argv[])
{
   argv_option options[]={ { "-weighted", true } };
   if (!extract_options(argc,argv,1,options) || argc!=2) {
      cerr << "usage: " << argv[0] << " <file> [ -weighted <mixed_edge_weight> ]" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      topaz::t_mixed_graph(p, options);
   } 
   catch (const std::exception& e) {
     cerr << e.what() << endl;
     return 1;
   }
   return 0;
}


// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
