| 116 | # return solution |
| 117 | |
| 118 | def getSolution(self, data, model): |
| 119 | solution = Solution() |
| 120 | solution.ObjVal = model.ObjVal |
| 121 | # X_ij |
| 122 | solution.X = [([0] * data.nodeNum) for j in range(data.nodeNum)] |
| 123 | # Y_ijk |
| 124 | solution.Y = [[([0] * data.nodeNum) for j in range(data.nodeNum)] for i in range(data.nodeNum)] |
| 125 | # U_i |
| 126 | solution.U = [[0] for i in range(data.nodeNum)] |
| 127 | # P_ij |
| 128 | solution.P = [[[0] for j in range(data.nodeNum)] for i in range(data.nodeNum)] |
| 129 | # T_i, T_i' |
| 130 | solution.T = [[0] for i in range(data.nodeNum)] |
| 131 | solution.Tt = [[0] for i in range(data.nodeNum)] |
| 132 | |
| 133 | a = U[0].x |
| 134 | for m in model.getVars(): |
| 135 | str = re.split(r"_", m.VarName) |
| 136 | if(str[0] == "X" and m.x == 1): |
| 137 | solution.X[int(str[1])][int(str[2])] = m.x |
| 138 | print(str, end = "") |
| 139 | print(" = %d" % m.x) |
| 140 | elif(str[0] == "Y" and m.x == 1): |
| 141 | solution.Y[int(str[1])][int(str[2])][int(str[3])] = m.x |
| 142 | elif(str[0] == "U" and m.x > 0) : |
| 143 | solution.U[int(str[1])] = m.x |
| 144 | elif(str[0] == "T" and m.x > 0): |
| 145 | solution.T[int(str[1])] = m.x |
| 146 | elif(str[0] == "Tt" and m.x > 0): |
| 147 | solution.Tt[int(str[1])] = m.x |
| 148 | elif(str[0] == "P" and m.x > 0): |
| 149 | solution.P[int(str[1])][int(str[2])] = m.x |
| 150 | |
| 151 | # get the route of truck and UAV |
| 152 | j = 0 |
| 153 | for i in range(data.nodeNum): |
| 154 | i = j # note that the variable is whether is a local variable or a global variable |
| 155 | # print("i = %d, j = %d" % (i, j), end = " ") |
| 156 | for j in range(data.nodeNum): |
| 157 | if(solution.X[i][j] == 1): |
| 158 | solution.route_Truck.append(i) |
| 159 | print(" %d -" % i, end = " ") |
| 160 | # print(" i = %d, j = %d" % (i, j)) |
| 161 | break |
| 162 | print(" 0") |
| 163 | solution.route_Truck.append(0) |
| 164 | |
| 165 | print("\n\n ------Route of UAV ------- ") |
| 166 | count = 0 |
| 167 | for i in range(data.nodeNum): |
| 168 | for j in range(data.nodeNum): |
| 169 | for k in range(data.nodeNum): |
| 170 | if(solution.Y[i][j][k] == 1): |
| 171 | count = count + 1 |
| 172 | #print("UAV %d : %d - %d - %d" % (count, i, j, k)) |
| 173 | temp = [i, j, k] |
| 174 | solution.route_UAV.append(temp) |
| 175 | |