data.generation.basic
¶
afccp.data.generation.basic
¶
Provides foundational random instance and parameter generation functions for the AFCCP framework. This module is designed to simulate realistic cadetβAFSC assignment problem instances, including utility structures, quotas, preferences, and optional extensions (bases, training, CASTLE-level curves).
Main Capabilities¶
-
Instance generation (
generate_random_instance
): Creates randomized cadet/AFSC datasets with merit scores, quotas, eligibility tiers, and preference matrices. Supports constraints such as "NRL only" generation or inclusion of extra base/training components. -
Value parameter generation (
generate_random_value_parameters
): Produces randomized Value-Focused Thinking (VFT) objective weights, targets, and value functions. Uses AFCCP'svalues
submodule to build piecewise-linear approximations of non-linear functions. -
Extra component generation (
generate_extra_components
): Adds bases, base capacities, training preferences, and course schedules for more complex problem variants. -
CASTLE integration (
generate_realistic_castle_value_curves
): Generates concave utility curves for CASTLE-level AFSC groupings to support strategic simulations.
Dependencies¶
- afccp.data.preferences β Builds cadet preference lists and utilities.
- afccp.data.adjustments β Adds parameter set modifications for alignment with AFCCP models.
- afccp.data.values β Creates weight functions and value function breakpoints.
- afccp.data.support β Provides shared helper utilities for data preparation.
- numpy, random, datetime, string, copy β For stochastic generation and data shaping.
Use Cases¶
- Rapid prototyping of AFCCP algorithms without relying on sensitive or incomplete real-world data.
- Benchmarking and stress-testing optimization methods.
- Building reproducible examples for tutorials, workshops, and documentation.
See Also¶
generate_random_instance(N=1600, M=32, P=6, S=6, generate_only_nrl=False, generate_extra=False)
¶
This procedure takes in the specified parameters (defined below) and then simulates new random "fixed" cadet/AFSC input parameters. These parameters are then returned and can be used to solve the VFT model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N |
number of cadets |
1600
|
|
M |
number of AFSCs |
32
|
|
P |
number of preferences allowed |
6
|
|
S |
number of Bases |
6
|
|
generate_only_nrl |
Only generate NRL AFSCs (default to False) |
False
|
|
generate_extra |
Whether to generate extra components (bases/IST). Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
model fixed parameters |
Source code in afccp/data/generation/basic.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
generate_random_value_parameters(parameters, num_breakpoints=24)
¶
Generate Random Value Parameters for a Cadet-AFSC Assignment Problem.
This function constructs a randomized set of value-focused thinking (VFT) parameters for a given cadet-AFSC matching instance. These include AFSC weights, cadet weights, value function definitions, and constraint structures across defined objectives. It supports a mix of manually assigned logic and randomized components and can be used to simulate plausible input conditions for testing the assignment algorithm.
Parameters¶
parameters : dict The problem instance parameters, including cadet/AFSC info, merit scores, eligibility, quotas, and utilities. num_breakpoints : int, optional Number of breakpoints to use in piecewise linear value functions, by default 24.
Returns¶
dict
A dictionary vp
containing generated value parameters, including objectives, weights, constraints,
value functions, and breakpoints.
Examples¶
vp = generate_random_value_parameters(parameters, num_breakpoints=16)
See Also¶
generate_afocd_value_parameters
: Adds tiered AFOCD objectives and fills in default VFT structure for a given instance.create_segment_dict_from_string
: Parses string definitions into nonlinear segment dictionaries for value functions.value_function_builder
: Linearizes nonlinear value functions using a fixed number of breakpoints.cadet_weight_function
: Creates weights across cadets based on merit scores and function type.afsc_weight_function
: Creates weights across AFSCs based on projected gains/losses and selected function type.
Source code in afccp/data/generation/basic.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
generate_extra_components(parameters)
¶
Generate additional components (bases, training courses, and timing factors) for a CadetCareerProblem instance.
This function augments the problem parameters with synthetic bases (locations), base capacities, cadet base preferences, training courses, and training start distributions. It also assigns weights to AFSC, base, and training preferences, enabling richer downstream optimization scenarios.
Parameters¶
parameters : dict
The problem parameter dictionary for a CadetCareerProblem
instance.
Must contain:
- M
: int
Number of AFSCs.
- N
: int
Number of cadets.
- S
: int
Number of bases to generate.
- pgl
: np.ndarray
PGL targets per AFSC.
- acc_grp
: np.ndarray
Accession group labels per AFSC (e.g., "Rated", "USSF", "NRL").
- usafa
: np.ndarray
Indicator for USAFA cadets.
Returns¶
dict
Updated parameters dictionary with additional fields:
- afsc_assign_base
: np.ndarray
Flags for AFSCs assigned to bases.
- bases
: np.ndarray
Names of generated bases.
- base_min
, base_max
: np.ndarray
Min/max base capacities per AFSC.
- base_preferences
: dict
Cadet-level base preference lists.
- b_pref_matrix
, base_utility
: np.ndarray
Matrices encoding cadet base preferences and utilities.
- baseline_date
: datetime.date
Baseline date for training course scheduling.
- training_preferences
, training_threshold
, base_threshold
: np.ndarray
Randomized cadet-level training/base thresholds and preferences.
- weight_afsc
, weight_base
, weight_course
: np.ndarray
Weights for AFSC vs base vs course assignment importance.
- training_start
: np.ndarray
Cadet training start dates (distribution differs for USAFA vs ROTC).
- courses
, course_start
, course_min
, course_max
: dict
Course identifiers, schedules, and capacities by AFSC.
- T
: np.ndarray
Number of courses per AFSC.
Workflow¶
-
Base Assignment
- Randomly selects which AFSCs require base-level assignments.
- Generates base names from Excel-style column naming (
A
,B
, ...,AA
, etc.). - Distributes base capacities (
base_min
,base_max
) across AFSCs.
-
Cadet Base Preferences
- Randomly assigns each cadet preferences over bases.
- Generates a preference matrix (
b_pref_matrix
) and base utilities (base_utility
).
-
Training Preferences
- Creates training preference labels (
Early
vsLate
) and thresholds. - Allocates random weights for AFSC, base, and training course priorities.
- Creates training preference labels (
-
Training Start Dates
- USAFA cadets start late May.
- ROTC cadets follow a spring/late graduation distribution.
-
Training Courses
- Generates course identifiers (random strings of letters).
- Randomizes start dates and max capacities.
- Computes
T
, the number of courses per AFSC.
Notes¶
baseline_date
is set to Jan 1 of the year after the current system year.- Weights are normalized per cadet to sum to 1.
- Utility values are randomized but ensure first-choice base has utility 1.0.
Examples¶
p = {'M': 5, 'N': 100, 'S': 3,
'pgl': np.array([10, 20, 15, 30, 25]),
'acc_grp': np.array(["NRL", "Rated", "NRL", "USSF", "NRL"]),
'usafa': np.random.randint(0, 2, size=100)}
p = generate_extra_components(p)
p.keys()
Example Output:
dict_keys([... 'bases', 'base_preferences', 'training_start', 'courses', 'T' ...])
Source code in afccp/data/generation/basic.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
|
generate_concave_curve(num_points, max_x)
¶
Generates x and y coordinates for a concave function.
Args: num_points (int): Number of points to generate. max_x (float): Maximum value along the x-axis.
Returns: tuple: (x_values, y_values) as numpy arrays.
Source code in afccp/data/generation/basic.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
|
generate_realistic_castle_value_curves(parameters, num_breakpoints: int = 10)
¶
Generate Concave Value Curves for CASTLE AFSCs.
Creates piecewise linear approximations of realistic concave value functions for each CASTLE-level AFSC. These curves are used to evaluate the marginal utility of inventory across AFSCs, enabling smooth optimization and modeling in the CASTLE simulation.
Parameters: parameters (dict): Problem instance parameters containing CASTLE AFSC groups and PGL values. num_breakpoints (int, optional): Number of breakpoints to use in the piecewise value curve. Defaults to 10.
Returns:
dict: A dictionary q
containing the following keys for each CASTLE AFSC:
- 'a'
: Array of x-values (inventory levels).
- 'f^hat'
: Array of corresponding y-values (utility).
- 'r'
: Number of breakpoints.
- 'L'
: Index array of breakpoints.
Example:
q = generate_realistic_castle_value_curves(parameters, num_breakpoints=12)
x_vals = q['a']['21A'] # x-values for AFSC 21A
y_vals = q['f^hat']['21A'] # corresponding utility values
See Also:
- generate_concave_curve
:
Generates a concave (diminishing returns) curve with specified number of points and max range.
Source code in afccp/data/generation/basic.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
|