OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
compare_cand.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <vector>
24#include <utility>
25#include <iostream>
26#include <algorithm>
27
28extern "C"
29{
30
31 void compare_cand(int *cand_n, int *cand_e, int ii_stok, int *cand_n_ref, int *cand_e_ref, int ii_stok_ref)
32 {
33 std::vector<std::pair<int, int>> candidates, candidates_ref;
34 for (int i = 0; i < ii_stok; ++i)
35 {
36 candidates.emplace_back(cand_n[i], cand_e[i]);
37 }
38 for (int i = 0; i < ii_stok_ref; ++i)
39 {
40 candidates_ref.emplace_back(cand_n_ref[i], cand_e_ref[i]);
41 }
42
43 std::sort(candidates.begin(), candidates.end());
44 std::sort(candidates_ref.begin(), candidates_ref.end());
45
46 int num_matches = 0;
47 int i = 0, j = 0;
48 while (i < ii_stok && j < ii_stok_ref)
49 {
50 if (candidates[i] == candidates_ref[j])
51 {
52 num_matches++;
53 ++i;
54 ++j;
55 }
56 else if (candidates[i] < candidates_ref[j])
57 {
58 ++i;
59 }
60 else
61 {
62 ++j;
63 }
64 }
65 std::cout << "number of candidates: " << ii_stok << "(ref: "<<ii_stok_ref<<")\n";
66 if (num_matches == ii_stok_ref)
67 {
68 std::cout << "Success: All candidates_ref are found in candidates.\n";
69 }
70 else
71 {
72 std::cout << "Failure: Not all candidates_ref are found in candidates.\n";
73 }
74 }
75}
void compare_cand(int *cand_n, int *cand_e, int ii_stok, int *cand_n_ref, int *cand_e_ref, int ii_stok_ref)