57 cout <<
"[Aleph Geometry Example] " << title <<
"\n";
58 cout <<
"============================================================\n";
75 const Point & p = it.get_current_vertex();
97 const Point & best_point,
104 file << fixed << setprecision(8);
105 file <<
"type,index,x,y,objective,wkt\n";
110 const Vertex & v = it.get_current_vertex();
111 file <<
"vertex," << idx <<
","
117 file <<
"optimum,-1,"
120 << best_value <<
",\n";
122 file <<
"polygon,-1,,,,\"";
128int main(
int argc,
char ** argv)
133 cout <<
"Feasible region of constraints:" << endl;
134 cout <<
" x >= 0, y >= 0, x <= 4, y <= 4, x + y <= 6" << endl;
135 cout <<
"Objective: maximize z = 3x + 2y" << endl;
148 assert(feasible.
size() >= 3);
150 cout <<
"\nFeasible polygon vertices:" << endl;
157 const Vertex & v = it.get_current_vertex();
171 cout <<
"\nOptimal vertex for z=3x+2y: ("
174 cout <<
"Optimal value z* = " << best_value << endl;
176 const char * csv_path =
177 (argc > 1) ? argv[1] :
"halfplane_intersection_output.csv";
178 if (
export_csv(csv_path, feasible, best_point, best_value))
179 cout <<
"CSV/WKT exported to: " << csv_path << endl;
181 cout <<
"Warning: cannot export CSV to: " << csv_path << endl;
183 cout <<
"STATUS: OK" << endl;
size_t size_t int32_t * out
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
bool has_curr() const noexcept
Return true if the iterator has current item.
Exact bounded intersection of half-planes.
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
A general (irregular) 2D polygon defined by a sequence of vertices.
const bool & is_closed() const
Check if the polygon is closed.
const size_t & size() const
Get the number of vertices.
A vertex in a polygon's doubly linked vertex list.
Computational geometry algorithms.
static Geom_Number objective(const Point &p)
static void write_polygon_wkt(ostream &out, const Polygon &poly)
static bool export_csv(const char *path, const Polygon &feasible, const Point &best_point, const Geom_Number &best_value)
static void print_banner(const char *title)
Main namespace for Aleph-w library functions.
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Iterator over the vertices of a polygon.