Beispiel #1
0
// eats up a comment, stream must start with "/*", eats everything until "*/"
void skip_comment(istream& in) {
    int i = in.get();
    int j = in.get();
    if (i != '/' || j != '*') {
        throw BadInputException("Bad comment start!");
    }
    while (in.good()) {
        in.ignore(numeric_limits<streamsize>::max(), '*'); //ignore everything until next '*'
        i = in.get();
        if (in.good() && i == '/') return; // successfully skipped comment
    }
    throw BadInputException("Incomplete comment!");
}
Beispiel #2
0
void save_matrix(map<Type::InputType, vector<vector<Integer> > >& input_map,
        InputType input_type, const string& type_string, const vector<vector<Integer> >& M) {
    //check if this type already exists
    if (exists_element(input_map, input_type)) {
        cerr << "Error: Multiple inputs of type \"" << type_string
                << "\" are not allowed!" << endl;
        throw BadInputException();
    }
    input_map[input_type] = M;
}
Beispiel #3
0
void process_constraint(const string& rel, const vector<mpq_class>& left, mpq_class right, const mpq_class modulus, 
                        map <Type::InputType, vector< vector<mpq_class> > >& input_map, bool forced_hom) {
    
    vector<mpq_class> row=left;
    bool inhomogeneous=false;
    if(right!=0 || rel=="<" || rel==">")
        inhomogeneous=true;
    string modified_rel=rel;
    bool strict_inequality=false;
    if(rel=="<"){
        strict_inequality=true;
        right-=1;
        modified_rel="<=";
        
    }
    if(rel==">"){
        strict_inequality=true;
        right+=1;
        modified_rel=">=";
    }
    if(strict_inequality && forced_hom){
            throw BadInputException("Strict inequality not allowed in hom_constraints!");
    }
    if(inhomogeneous || forced_hom)
        row.push_back(-right); // rhs --> lhs
    if(modified_rel=="<="){ // convert <= to >=
        for(size_t j=0; j<row.size();++j)
            row[j]=-row[j];
        modified_rel=">=";
    }
    if(rel=="~")
        row.push_back(modulus);

    if(inhomogeneous && !forced_hom){
        if(modified_rel=="="){
            append_row(row,input_map,Type::inhom_equations);
            return;
        }
        if(modified_rel==">="){
            append_row(row,input_map,Type::inhom_inequalities);
            return;
        }
        if(modified_rel=="~"){
            append_row(row,input_map,Type::inhom_congruences);
            return;
        }
    }
    else {
        if(modified_rel=="="){
            append_row(row,input_map,Type::equations);
            return;
        }
        if(modified_rel==">="){
            append_row(row,input_map,Type::inequalities);
            return;
        }
        if(modified_rel=="~"){
            append_row(row,input_map,Type::congruences);
            return;
        }                
    }
    throw BadInputException("Illegal constrint type "+rel+" !");
}
Beispiel #4
0
map <Type::InputType, vector< vector<Integer> > > readNormalizInput (istream& in, OptionsHandler& options) {

    string type_string;
    long i,j;
    long nr_rows,nr_columns;
    InputType input_type;
    Integer number;
    ConeProperty::Enum cp;

    map<Type::InputType, vector< vector<Integer> > > input_map;
    typename map<Type::InputType, vector< vector<Integer> > >::iterator it;

    in >> std::ws;  // eat up any leading white spaces
    int c = in.peek();
    if ( c == EOF ) {
        cerr << "Error: Empty input file!" << endl;
        throw BadInputException();
    }
    bool new_input_syntax = !std::isdigit(c);

    if (new_input_syntax) {
        long dim;
        while (in.peek() == '/') {
            skip_comment(in);
            in >> std::ws;
        }
        in >> type_string;
        if (!in.good() || type_string != "amb_space") {
            cerr << "Error: First entry must be \"amb_space\"!" << endl;
            throw BadInputException();
        }
        in >> dim;
        if (!in.good() || dim <= 0) {
            cerr << "Error: Bad amb_space value!" << endl;
            throw BadInputException();
        }
        while (in.good()) {
            in >> std::ws;  // eat up any leading white spaces
            c = in.peek();
            if (c == EOF) break;
            if (c == '/') {
                skip_comment(in);
            } else {
                in >> type_string;
                if (in.fail()) {
                    cerr << "Error: Could not read type string!" << endl;
                    throw BadInputException();
                }
                if (std::isdigit(c)) {
                    cerr << "Error: Unexpected number "<< type_string << " when expecting a type !" << endl;
                    throw BadInputException();
                }
                if (isConeProperty(cp, type_string)) {
                    options.activateInputFileConeProperty(cp);
                    continue;
                }
                if (type_string == "BigInt") {
                    options.activateInputFileBigInt();
                    continue;
                }
                if (type_string == "total_degree") {
                    input_type = Type::grading;
                    save_matrix(input_map, input_type, type_string, vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),1)));
                    continue;
                }
                if (type_string == "nonnegative") {
                    input_type = Type::signs;
                    save_matrix(input_map, input_type, type_string, vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),1)));
                    continue;
                }


                input_type = to_type(type_string);

                if (type_is_vector(input_type)) {
                    nr_rows = 1;
                    in >> std::ws;  // eat up any leading white spaces
                    c = in.peek();
                    if (!std::isdigit(c) && c != '-') {
                        string vec_kind;
                        in >> vec_kind;
                        if (vec_kind == "unit_vector") {
                            long pos = 0;
                            in >> pos;
                            if (in.fail()) {
                                cerr << "Error while reading " << type_string << " as a unit_vector form the input!" << endl;
                                throw BadInputException();
                            }

                            vector< vector<Integer> > e_i = vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),0));
                            if (pos < 1 || pos > static_cast<long>(e_i[0].size())) {
                                cerr << "Error while reading " << type_string << " as a unit_vector "<< pos <<" form the input!" << endl;
                                throw BadInputException();
                            }
                            pos--; // in input file counting starts from 1
                            e_i[0].at(pos) = 1;
                            save_matrix(input_map, input_type, type_string, e_i);
                            continue;
                        }
                    }
                } else {
                    in >> nr_rows;
                }
                nr_columns = dim + type_nr_columns_correction(input_type);
                if(in.fail() || nr_rows < 0) {
                    cerr << "Error while reading " << type_string << " (a "<<nr_rows<<"x"<<nr_columns<<" matrix) form the input!" << endl;
                    throw BadInputException();
                }
                vector< vector<Integer> > M(nr_rows,vector<Integer>(nr_columns));
                for(i=0; i<nr_rows; i++){
                    for(j=0; j<nr_columns; j++) {
                        in >> M[i][j];
                    }
                }
                save_matrix(input_map, input_type, type_string, M);
            }
Beispiel #5
0
InputType to_type(const std::string& type_string) {

    if ( type_string=="0" || type_string=="1" || type_string=="2" || type_string=="3"
      || type_string=="4" || type_string=="5" || type_string=="6"
      || type_string=="hyperplanes"
      || type_string=="10") {
        throw BadInputException("Error: deprecated type \"" + type_string
                + "\", please use new type string!");
    }

    if (type_string=="0"||type_string=="integral_closure") {
        return Type::integral_closure;
    }
    if (type_string=="polyhedron") {
        return Type::polyhedron;
    }
    if (type_string=="1"||type_string=="normalization") {
        return Type::normalization;
    }
    if (type_string=="2"||type_string=="polytope") {
        return Type::polytope;
    }
    if (type_string=="3"||type_string=="rees_algebra") {
        return Type::rees_algebra;
    }
    if (type_string=="4"||type_string=="hyperplanes" ||type_string=="inequalities") {
        return Type::inequalities;
    }
    if (type_string=="strict_inequalities") {
         return Type::strict_inequalities;
    }
    if (type_string=="strict_signs") {
        return Type::strict_signs;
    }
    if (type_string=="inhom_inequalities") {
        return Type::inhom_inequalities;
    }
    if (type_string=="dehomogenization") {
         return Type::dehomogenization;
    }
    if (type_string=="5"||type_string=="equations") {
        return Type::equations;
    }
    if (type_string=="inhom_equations") {
        return Type::inhom_equations;
    }
    if (type_string=="6"||type_string=="congruences") {
        return Type::congruences;
    }
    if (type_string=="inhom_congruences") {
        return Type::inhom_congruences;
    }
    if (type_string=="signs") {
        return Type::signs;
    }
    if (type_string=="10"||type_string=="lattice_ideal") {
        return Type::lattice_ideal;
    }
    if (type_string=="grading") {
        return Type::grading;
    }
    if (type_string=="excluded_faces") {
        return Type::excluded_faces;
    }
    if (type_string=="lattice") {
        return Type::lattice;
    }
    if (type_string=="saturation") {
        return Type::saturation;
    }
    if (type_string=="cone") {
        return Type::cone;
    }
    if (type_string=="offset") {
        return Type::offset;
    }
    if (type_string=="vertices") {
        return Type::vertices;
    }
    if (type_string=="support_hyperplanes") {
        return Type::support_hyperplanes;
    }
    if (type_string=="cone_and_lattice") {
        return Type::cone_and_lattice;
    }
    if (type_string=="subspace") {
        return Type::subspace;
    }
    
    if (type_string=="open_facets") {
        return Type::open_facets;
    }
    
    if (type_string=="projection_coordinates") {
        return Type::projection_coordinates;
    }
    
    if (type_string=="hilbert_basis_rec_cone") {
        return Type::hilbert_basis_rec_cone;
    }
    
    if (type_string=="extreme_rays") {
        return Type::extreme_rays;
    }
    
    if (type_string=="scale") {
        return Type::scale;
    }

    throw BadInputException("Unknown type \"" + type_string + "\"!");
    return Type::integral_closure;
}