How to control the function parameters via macro definitions?

Hi, for a project, I need to use 3 different size arrays and matrices. Actually, the project is a homework, p-median problem here:

Solving the p-Median Problem using Local Search
In this homework, you are going to solve the p-median problem for three data sets. They are called eil51, eil76, and eil101, and consist of 51, 76, and 101 customer locations, respectively. Each data set includes the x-coordinates, y-coordinates, and demand of customers. Customer locations are also potential facility location for opening facilities. For each data set, you are going to locate 4, 6, and 8 facilities. This makes a total of 9 instances (3 data sets, 3 different p values). The distances between potential facility locations and customer locations are measure via Euclidean distance (not Squared Euclidean distance). This is important because the optimal objective values I will provide are also based on the Euclidean distance. Please round all the distance values to two digits after the decimal point. This is also true for the objective values.


So I created each arrays and 2D arrays and wanted to control the arrays passing to the functions via macro definition:

1
2
#define FACILITY_NUMBER 4
#define ZONE 51 


and this is where I get the error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void cadmX()
{
    //
    switch (ZONE)
    {
        //
    case 51:
        calculateAllDistanceMatricesX(distMat51, Rx51, Ry51);
        break;
    case 76:
        calculateAllDistanceMatricesX(distMat76, Rx76, Ry76);
        break;
    case 101:
        calculateAllDistanceMatricesX(distMat101, Rx101, Ry101);
        break;
    }
}


for example, compiler throws error for case 76 and 101. I can not understand, I am not going to use them since my macro is defined as 51. So why did I get this error? And secondly, If this is a fact that I can not solve, what do you suggest? Thanks.
Last edited on
int fix = ZONE;

switch(fix)

or you can do it with #if type statements. This is ugly but its better because you compile for the setting directly, without do-nothing code and conditionals off a constant.


switch is stubborn and it ONLY works on integer variable types.
you can't do
switch (3)
(which is what you are doing, when it resolves the macro)
Last edited on
Topic archived. No new replies allowed.