I am using Petsc Ksp routines.
I construct an operator using MatSetValuesStencil, where in each call of this function I specify one row matrix values of length 5.
There is a case where I sometimes need to completely replace a row from a 5 length stencil to a 3 length one. Will INSERT_VALUES mode leave the two values on non changed positions or it will discard them to zero?
The elements of the matrix that are not specified in the arguments idxm and idxn of the function MatSetValuesStencil(...) are left unchanged, even if INSERT_VALUES is used.
Here is a little code starting from ksp_ex29 to test it :
static char help[] = "Does INSERT_VALUES changes the whole row ? No.\n\n";
#include <petscdm.h>
#include <petscdmda.h>
#include <petscksp.h>
extern PetscErrorCode ComputeMatrix42(DM da,Mat jac);
extern PetscErrorCode ComputeMatrix(DM da,Mat jac);
#undef __FUNCT__
#define __FUNCT__ "main"
int main(int argc,char **argv)
{
DM da;
PetscErrorCode ierr;
Mat matrix;
PetscInitialize(&argc,&argv,(char*)0,help);
ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC,DMDA_STENCIL_STAR,-3,-3,PETSC_DECIDE,PETSC_DECIDE,1,1,0,0,&da);CHKERRQ(ierr);
DMCreateMatrix(da,&matrix);
ComputeMatrix(da,matrix);
PetscPrintf(PETSC_COMM_WORLD,"A matrix of negative terms : \n");
MatView(matrix, PETSC_VIEWER_STDOUT_WORLD );
ComputeMatrix42(da,matrix);
PetscPrintf(PETSC_COMM_WORLD,"The diagonal, i-1 and i+1 are set to 42 : \n");
MatView(matrix, PETSC_VIEWER_STDOUT_WORLD );
ierr = DMDestroy(&da);CHKERRQ(ierr);
ierr = MatDestroy(&matrix);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "ComputeMatrix"
PetscErrorCode ComputeMatrix(DM da,Mat jac)
{
PetscErrorCode ierr;
PetscInt i,j,mx,my,xm,ym,xs,ys;
PetscScalar v[5];
MatStencil row, col[5];
PetscFunctionBeginUser;
ierr = DMDAGetInfo(da,0,&mx,&my,0,0,0,0,0,0,0,0,0,0);CHKERRQ(ierr);
ierr = DMDAGetCorners(da,&xs,&ys,0,&xm,&ym,0);CHKERRQ(ierr);
for (j=ys; j<ys+ym; j++) {
for (i=xs; i<xs+xm; i++) {
row.i = i; row.j = j;
v[0] = -1; col[0].i = i; col[0].j = j-1;
v[1] = -1; col[1].i = i-1; col[1].j = j;
v[2] = -13; col[2].i = i; col[2].j = j;
v[3] = -1; col[3].i = i+1; col[3].j = j;
v[4] = -1; col[4].i = i; col[4].j = j+1;
ierr = MatSetValuesStencil(jac,1,&row,5,col,v,INSERT_VALUES);CHKERRQ(ierr);
}
}
ierr = MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "ComputeMatrix42"
PetscErrorCode ComputeMatrix42(DM da,Mat jac)
{
PetscErrorCode ierr;
PetscInt i,j,mx,my,xm,ym,xs,ys;
PetscScalar v[3];
MatStencil row, col[3];
PetscFunctionBeginUser;
ierr = DMDAGetInfo(da,0,&mx,&my,0,0,0,0,0,0,0,0,0,0);CHKERRQ(ierr);
ierr = DMDAGetCorners(da,&xs,&ys,0,&xm,&ym,0);CHKERRQ(ierr);
for (j=ys; j<ys+ym; j++) {
for (i=xs; i<xs+xm; i++) {
row.i = i; row.j = j;
v[0] = 42; col[0].i = i-1; col[0].j = j;
v[1] = 42; col[1].i = i; col[1].j = j;
v[2] = 42; col[2].i = i+1; col[2].j = j;
ierr = MatSetValuesStencil(jac,1,&row,3,col,v,INSERT_VALUES);CHKERRQ(ierr);
}
}
ierr = MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
Compile it with the following makefile :
include ${PETSC_DIR}/conf/variables
include ${PETSC_DIR}/conf/rules
main: main.o chkopts
-${CLINKER} -o main main.o ${PETSC_LIB}
${RM} main.o
Output :
A matrix of negative terms :
Mat Object: 1 MPI processes
type: seqaij
row 0: (0, -13) (1, -1) (2, -1) (3, -1) (6, -1)
row 1: (0, -1) (1, -13) (2, -1) (4, -1) (7, -1)
row 2: (0, -1) (1, -1) (2, -13) (5, -1) (8, -1)
row 3: (0, -1) (3, -13) (4, -1) (5, -1) (6, -1)
row 4: (1, -1) (3, -1) (4, -13) (5, -1) (7, -1)
row 5: (2, -1) (3, -1) (4, -1) (5, -13) (8, -1)
row 6: (0, -1) (3, -1) (6, -13) (7, -1) (8, -1)
row 7: (1, -1) (4, -1) (6, -1) (7, -13) (8, -1)
row 8: (2, -1) (5, -1) (6, -1) (7, -1) (8, -13)
The diagonal, i-1 and i+1 are set to 42 :
Mat Object: 1 MPI processes
type: seqaij
row 0: (0, 42) (1, 42) (2, 42) (3, -1) (6, -1)
row 1: (0, 42) (1, 42) (2, 42) (4, -1) (7, -1)
row 2: (0, 42) (1, 42) (2, 42) (5, -1) (8, -1)
row 3: (0, -1) (3, 42) (4, 42) (5, 42) (6, -1)
row 4: (1, -1) (3, 42) (4, 42) (5, 42) (7, -1)
row 5: (2, -1) (3, 42) (4, 42) (5, 42) (8, -1)
row 6: (0, -1) (3, -1) (6, 42) (7, 42) (8, 42)
row 7: (1, -1) (4, -1) (6, 42) (7, 42) (8, 42)
row 8: (2, -1) (5, -1) (6, 42) (7, 42) (8, 42)
I am using PETSC 3.5.2.
Related
sorry for bothering but I'm stuck in this, the idea is:
Insert in console numbers from 1 to 9 (it doesn't matter the order or if it repeat), and create a 2 dimensional array BUT it has to be order in SPIRAL INVERSE (starting from the center)
EXAMPLE 1:
INPUT (enter numbers without spaces):
123456789
OUTPUT:
789
612
543
EXAMPLE 2:
INPUT (enter numbers without spaces):
12345678976
OUTPUT:
7897
6126
543
I MADE THIS:
for getting the numbers and trying to put in vector of 2 dimensions but after that point I don't know how I should make the spiral...
attached my code:
#include <iostream>
using namespace std;
int main()
{
int a[] = { 1,2,3,4,5,6,7,8,9 };
int b[3][3];
int k = 0;
int i, j;
int arrSize = sizeof(a) / sizeof(a[0]);
cout << arrSize;
cout << endl;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
b[i][j] = a[k++];
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
cout << b[i][j];
cout << endl;
}
}
With this code I be able to put into a 2D array.
Thank you in advance, for your time and patience with me!
The following program lists the (x, y) sequence for the spiral. The first list using the starting points located at (0, 0). The second moves the starting of spiral to the position of (minimum.x, minimum.y). The minimum keeps the coordinate of the left-bottom element.
You may observe the rule of spiral in the program. A position (x,y) first starts at (n, n-1) where n is the nth loop of the spiral. First, move the position downward, --y, untile y reach -n; then move x left until x = -n; then move y upward until y=n; finally, move x right until x = n. In the following program max(n) set = 4, there are 4 spiral loops. You may adjust this parameter n to fit you purpose.
The total number of each spiral loop = 8*n, except the inner most loop (0,0), the number = 1. Therefore, the number of element of spiral = 1 + 8*1 + 8*2 + 8*3 +.... You have first to determine the loops of spiral by the length of input string L, The loops number is eqaul to `n = ( (L-1) / 8 + 1 );` or `n = ( (L-1) / 8 );` if no remaider left.
#include <iostream>
#include <vector>
struct int2 {
int x, y;
int2():x(0), y(0) {}
int2(const int a, const int b):x(a), y(b) {}
int2& operator=(const int2&) = default;
void print() const {std::cout << "( " << x <<", " << y << ") "; }
int2& operator+=(const int2&a) { this->x += a.x ; this->y += a.y; return *this;}
int2& operator-() {x = -x; y = -y; return *this;}
};
int main()
{
std::vector<int2> spiral;
int2 pos, minimum;
int n;
pos = int2(0,0);
minimum = pos;
spiral.push_back(pos);
for (n=1; n<5; n++)
{
pos = int2( n, n-1); // starting point for ith loop
spiral.push_back(pos);
while (pos.y > -n) {--pos.y; spiral.push_back(pos); if (pos.y < minimum.y) minimum.y = pos.y;}
while (pos.x > -n) {--pos.x; spiral.push_back(pos); if (pos.x < minimum.x) minimum.x = pos.x; }
while (pos.y < n) {++pos.y; spiral.push_back(pos); }
while (pos.x < n) {++pos.x; spiral.push_back(pos); }
}
-minimum;
std::cout << "center at (0, 0)\n";
for (int i=0; i<spiral.size(); i++) spiral[i].print();
std::cout<<std::endl;
for (int i=0; i<spiral.size(); i++) spiral[i] += minimum;
std::cout << "center at "; minimum.print(); std::cout<<std::endl;
for (int i=0; i<spiral.size(); i++) spiral[i].print();
std::cout<<std::endl;
return 0;
}
This above (x, y) positions provide you the 2-d sequence array[x][y] to write you char forming a spiral structure.
center at (0, 0)
( 0, 0) ( 1, 0) ( 1, -1) ( 0, -1) ( -1, -1) ( -1, 0) ( -1, 1) ( 0, 1) ( 1, 1) ( 2, 1) ( 2, 0) ( 2, -1) ( 2, -2) ( 1, -2) ( 0, -2) ( -1, -2) ( -2, -2) ( -2, -1) ( -2, 0) ( -2, 1) ( -2, 2) ( -1, 2) ( 0, 2) ( 1, 2) ( 2, 2) ( 3, 2) ( 3, 1) ( 3, 0) ( 3, -1) ( 3, -2) ( 3, -3) ( 2, -3) ( 1, -3) ( 0, -3) ( -1, -3) ( -2, -3) ( -3, -3) ( -3, -2) ( -3, -1) ( -3, 0) ( -3, 1) ( -3, 2) ( -3, 3) ( -2, 3) ( -1, 3) ( 0, 3) ( 1, 3) ( 2, 3) ( 3, 3) ( 4, 3) ( 4, 2) ( 4, 1) ( 4, 0) ( 4, -1) ( 4, -2) ( 4, -3) ( 4, -4) ( 3, -4) ( 2, -4) ( 1, -4) ( 0, -4) ( -1, -4) ( -2, -4) ( -3, -4) ( -4, -4) ( -4, -3) ( -4, -2) ( -4, -1) ( -4, 0) ( -4, 1) ( -4, 2) ( -4, 3) ( -4, 4) ( -3, 4) ( -2, 4) ( -1, 4) ( 0, 4) ( 1, 4) ( 2, 4) ( 3, 4) ( 4, 4)
center at ( 4, 4)
( 4, 4) ( 5, 4) ( 5, 3) ( 4, 3) ( 3, 3) ( 3, 4) ( 3, 5) ( 4, 5) ( 5, 5) ( 6, 5) ( 6, 4) ( 6, 3) ( 6, 2) ( 5, 2) ( 4, 2) ( 3, 2) ( 2, 2) ( 2, 3) ( 2, 4) ( 2, 5) ( 2, 6) ( 3, 6) ( 4, 6) ( 5, 6) ( 6, 6) ( 7, 6) ( 7, 5) ( 7, 4) ( 7, 3) ( 7, 2) ( 7, 1) ( 6, 1) ( 5, 1) ( 4, 1) ( 3, 1) ( 2, 1) ( 1, 1) ( 1, 2) ( 1, 3) ( 1, 4) ( 1, 5) ( 1, 6) ( 1, 7) ( 2, 7) ( 3, 7) ( 4, 7) ( 5, 7) ( 6, 7) ( 7, 7) ( 8, 7) ( 8, 6) ( 8, 5) ( 8, 4) ( 8, 3) ( 8, 2) ( 8, 1) ( 8, 0) ( 7, 0) ( 6, 0) ( 5, 0) ( 4, 0) ( 3, 0) ( 2, 0) ( 1, 0) ( 0, 0) ( 0, 1) ( 0, 2) ( 0, 3) ( 0, 4) ( 0, 5) ( 0, 6) ( 0, 7) ( 0, 8) ( 1, 8) ( 2, 8) ( 3, 8) ( 4, 8) ( 5, 8) ( 6, 8) ( 7, 8) ( 8, 8)
I came across a situation that I couldn't explain why. I have a vector<vector<pair<int, int> > > parent that indicates parent of a specific cell. I have following code:
// (1, 0), (1, 2), (1, 2)
// (1, 2), (-1, -1), (1, 2)
// (-1, -1), (2, 1), (-1, -1)
vector<vector<pair<int, int> > > nums = {
{make_pair(1, 0), make_pair(1, 2), make_pair(1, 2)},
{make_pair(1, 2), make_pair(-1, -1), make_pair(1, 2)},
{make_pair(-1, -1), make_pair(2, 1), make_pair(-1, -1)}};
int r = 0;
int c = 1;
while (nums[r][c] != make_pair(r, c)) {
cout << nums[r][c].first << " " << nums[r][c].second << endl; // 1, 2
r = nums[r][c].first; // 1
c = nums[r][c].second; // -1
cout << "r: " << r << " c: " << c << endl;
}
I 'm not sure why in the first iteration of while loop for c = nums[r][c].second; it returns -1 instead of 2.
In first iteration,
r=num[0][1].first = 1.
Therefore
c=num[1][1].second = - 1.
I'm working on a project which takes a string input from the user of coordinates.
example of input:
"Polygons = [(1, 1), (4, 1), (4, 5), (3,5), (1, 5); (5,3), (3, 4), (6, 4), (6, 12), (3, 12)]"
One of the functions that I am making is checking the minimum/maximum X, which is clearly any number after a "(", however the problem that's bugging me is converting what's after the ( into a float to use it in calculations and number comparisons.
#include <iostream>
#include "string"
#include <stdlib.h>
#include <cstdlib>
using namespace std;
//Using a constant string for testing
string Polygon_Input = "Polygons = [(1, 1), (4, 1), (4, 5), (3,5), (1, 5); (5,3), (3, 4), (6, 4), (6, 12), (3, 12)]";
string Operation;
float Min_X = 9999;
int main()
{
getline(cin, Operation);
if (Operation == "Minimum_X")
{
for (int i; i <= Polygon_Input.length(); i++)
{
if (Polygon_Input[i] == '(')
{
float X = Polygon_Input[i + 1];
if (X < Min_X)
{
Min_X = X;
}
}
}
cout << Min_X;
}
That's not working, it always prints out 49 as Min_X
I also tried the same code with one modification, but still doesn't work.
if (Polygon_Input[i] == '(')
{
string X_As_String = Polygon_Input.substr(i + 1, i + 1);
float X = atof(X_As_String.c_str());
if (X < Min_X)
{
Min_X = X;
}
First of all, there are several problems in your code.
float Min_X = 9999;
The minimum value must be in the list. Initialize the first element as the minimum value and compare it with the rest.
if (X < Min_X)
The value X is int whereas Min_X is float. Don't compare int with float. Declare both as float and then cast if you would like an integer number.
for (int i=0; i <= Polygon_Input.length(); i++)
Pay attention to <=. It should be <.
Now the solution for your problem is
//#include <limits> // no need for this
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdlib>
using namespace std;
//Using a constant string for testing
string Polygon_Input = "Polygons = [(1, 1), (4, 1), (4, 5), (3,5), (1, 5); (5,3), (3, 4), (6, 4), (6, 12), (3, 12)]";
string Operation("Minimum_X");
//float Min_X = 9999; ?????? Why
float Min_X;
bool flag(true);
int main()
{
//getline(cin, Operation); // commented out for test
if (Operation == "Minimum_X")
{
for (int i=0; i < Polygon_Input.size(); i++)
{
if ( Polygon_Input[i] == '(' )
{
// extract X values (i.e. the first co-ordinate of a point )
std::string temp = Polygon_Input.substr(i+1, Polygon_Input.find_first_of(",",i)-i-1 );
// convert strig to float
float X = std::stof(temp);
// store first element and compare it with the rest
if(flag){
Min_X = X;
flag=false;
}
// int X = Polygon_Input[i + 1] - '0'; ????? What is this?
if (X < Min_X)
{
Min_X = X;
}
}
}
cout << Min_X << endl;
}
return 0;
}
The output is
1
which the minimum X value in the list. This code handles float values as well (i.e. (3.45, 4)). Try different values for checking.
I'm trying to change the weight of edges in my grid_graph but fail to access the edge_descriptor with:
std::pair<bEdgeDescriptor, bool> ed_right = boost::edge(bVertexDescriptor {{i - 1, j, k}}, bVertexDescriptor {{i, j, k}}, grid);
where grid is boost::grid_graph<3>
Then I find out the grid_graph does not support this. In order to make use of the astar_search, is there any convenient way to access edge_descriptor with given vertex_descriptor in boost::grid_graph but not adjacency_list?
You can get the in/out edges for any particular node:
http://www.boost.org/doc/libs/1_63_0/libs/graph/doc/grid_graph.html#indexing
// Get the out-edge associated with vertex and out_edge_index
Traits::edge_descriptor
out_edge_at(Traits::vertex_descriptor vertex,
Traits::degree_size_type out_edge_index,
const Graph& graph);
// Get the out-edge associated with vertex and in_edge_index
Traits::edge_descriptor
in_edge_at(Traits::vertex_descriptor vertex,
Traits::degree_size_type in_edge_index,
const Graph& graph);
Demo using a 3d 4x4x4 grid with non-wrapping dimensions (this show-cases that the degree of nodes on the edges is lower):
Live On Coliru
#include <boost/graph/grid_graph.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
using Grid = boost::grid_graph<3>;
using Traits = boost::graph_traits<Grid>;
using vertex_descriptor = Grid::vertex_descriptor;
using edge_descriptor = Grid::edge_descriptor;
static inline std::ostream& operator<<(std::ostream& os, vertex_descriptor const& vd) {
return os << "(" << vd[0] << ", " << vd[1] << ", " << vd[2] << ")";
}
void print_in_edges(vertex_descriptor vd, Grid const& grid) {
for (Traits::degree_size_type ei = 0; ei < in_degree(vd, grid); ++ei) {
auto ed_left = in_edge_at(vd, ei, grid);
std::cout << "Detected in edge: " << ed_left.first << " -> " << ed_left.second << "\n";
}
}
void print_out_edges(vertex_descriptor vd, Grid const& grid) {
for (Traits::degree_size_type ei = 0; ei < out_degree(vd, grid); ++ei) {
auto ed_left = out_edge_at(vd, ei, grid);
std::cout << "Detected out edge: " << ed_left.first << " -> " << ed_left.second << "\n";
}
}
int main() {
Grid grid({ { 4, 4, 4 } }, false);
print_in_edges({{ 2, 2, 2 } }, grid);
print_out_edges({{ 2, 2, 2 } }, grid);
std::cout << "----\n";
print_in_edges({{ 0, 0, 0 } }, grid);
print_out_edges({{ 0, 0, 0 } }, grid);
}
Prints:
Detected in edge: (1, 2, 2) -> (2, 2, 2)
Detected in edge: (3, 2, 2) -> (2, 2, 2)
Detected in edge: (2, 1, 2) -> (2, 2, 2)
Detected in edge: (2, 3, 2) -> (2, 2, 2)
Detected in edge: (2, 2, 1) -> (2, 2, 2)
Detected in edge: (2, 2, 3) -> (2, 2, 2)
Detected out edge: (2, 2, 2) -> (1, 2, 2)
Detected out edge: (2, 2, 2) -> (3, 2, 2)
Detected out edge: (2, 2, 2) -> (2, 1, 2)
Detected out edge: (2, 2, 2) -> (2, 3, 2)
Detected out edge: (2, 2, 2) -> (2, 2, 1)
Detected out edge: (2, 2, 2) -> (2, 2, 3)
----
Detected in edge: (1, 0, 0) -> (0, 0, 0)
Detected in edge: (0, 1, 0) -> (0, 0, 0)
Detected in edge: (0, 0, 1) -> (0, 0, 0)
Detected out edge: (0, 0, 0) -> (1, 0, 0)
Detected out edge: (0, 0, 0) -> (0, 1, 0)
Detected out edge: (0, 0, 0) -> (0, 0, 1)
I am struggling to convert a 2D array of points in a 1D array of ints. I wrote a wrapper class to do that for me (Array3D), which does the mapping for me with filling the underlying buffer, but it looks like the indexing is totally wrong, since when I print my 2D array and in comparison the buffer, it gives me different outputs.
The 2D point array has dimensions steps × number_of_robots. Therefore, the 1D buffer has
a length of steps × number_of_robots × 2.
Idea is that
buffer[index(x,y,0)] corresponds to points[index(x,y)].x
buffer[index(x,y,1)] corresponds to points[index(x,y)].y
The output is wrong, since it should be identical when I print out the 2D point array and the 1D buffer. I read the row of points from a file, and therefore, they totally should be identical.
The points are derived from the input read by a file. How that is done seems unimportant. Fact is, that the output of main.cpp is:
(0, 4) (0, 5) (1, 5) (2, 5) (2, 4) (3, 4) (2, 4) (2, 3) (2, 2)
(4, 0) (4, -1) (4, 0) (4, 1) (3, 1) (4, 1) (4, 2) (3, 2) (2, 2)
(0, 2) (0, 3) (1, 2) (2, 2) (2, 2) (3, 3) (2, 2) (2, 2) (2, 2)
(1, 2) (2, 2) (2, 2) (3, 3) (2, 2) (2, 2) (2, 2) (3, 3) (2, 2)
point.cpp
Point::Point(int a, int b) {
x = a;
y = b;
}
Array3D.cpp
template<class T>
int Array3D<T>::index(int x,int y, int z) {
return (x * ydim + y) * zdim + z;
}
template<class T>
T Array3D<T>::get( int x, int y, int z) {
return buffer[index(x,y,z)];
}
template<class T>
void Array3D<T>::set( int x, int y, int z ,T n) {
buffer[index(x,y,z)] = n;
}
Harvester.cpp
int Harvester::index(int t, int n) {
return t*number_of_robots + n;
}
void Harvester::extract(Array3D<int> *array) {
Point p;
for(int t = 0; t < steps; t++ ) {
for(int n = 0; n < number_of_robots; n++) {
p = data[index(t,n)];
array->set(t,n,0,p.x);
array->set(t,n,1,p.x);
}
}
}
void Harvester::read_points(string filename) {
string line;
ifstream input;
input.open(filename.c_str());
input >> number_of_robots;
int x, y;
for(int n = 0; n < number_of_robots; n++) {
if(input >> x >> y) {
data[index(0,n)].x = x;
data[index(0,n)].y = y;
//cout << x << " " << y << endl;
} else {
cout << "Your file is bad, and you should feel bad!";
return;
}
}
}
void Harvester::print_harvest() {
for (int n = 0; n < number_of_robots; n++) {
for (int t = 0; t < steps; t++) {
data[index(t,n)].dump();
}
cout << endl;
}
cout << endl;
}
robots_002.txt
2
0 4
4 0
main.cpp
int main() {
int mission_time;
int number_of_robots;
Point goal;
string path;
bool print = true;
int choice = 2;
mission_time = 8;
number_of_robots = 2;
goal.x = 2;
goal.y = 2;
path = "robots_002.txt";
int steps = mission_time + 1;
Harvester h(mission_time, number_of_robots, goal);
h.read_points("fixtures/" + path);
h.run();
int *buffer = new int[steps * number_of_robots * 2];
Array3D<int> arr(steps, number_of_robots, 2, buffer);
h.extract(&arr);
h.print_harvest();
for (int n = 0; n < number_of_robots; n++) {
for (int t = 0; t < steps; t++) {
printf("(%d, %d)\t", arr.get(t, n, 0), arr.get(t, n, 1));
}
cout << endl;
}
return 0;
}
still looking through but quick observation. In Harverster::extract, you are setting both to p.x
void Harvester::extract(Array3D<int> *array) {
Point p;
for(int t = 0; t < steps; t++ ) {
for(int n = 0; n < number_of_robots; n++) {
p = data[index(t,n)];
array->set(t,n,0,p.x);
array->set(t,n,1,p.x); //<-- im thinking you want this to be p.y
}
}
}