Skip to content

Commit

Permalink
Minor refactor and cleanup
Browse files Browse the repository at this point in the history
* Refactor "from" loop into "until" loop and separate statements, to shorten line length.
* Remove trailing spaces or periods where the style is to omit them.
  • Loading branch information
maneatingape committed Jul 30, 2020
1 parent 96e1cc6 commit fa0c19a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
**Please check the PR fulfills these basic requirements**

- [ ] PR has merged or rebased most recent commits from upstream repo .
- [ ] The commit messages are descriptive, helpful and informative.
- [ ] The code follows the code style of this project.
- [ ] PR has merged or rebased most recent commits from upstream repo
- [ ] The commit messages are descriptive, helpful and informative
- [ ] The code follows the code style of this project
- [ ] README has been updated (for features)

**What kind of change does this PR introduce?**
Expand Down
2 changes: 1 addition & 1 deletion src/hill_climb.ks
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export("grid_search", grid_search@).
local function line_search {
parameter cost, x, step_size, step_threshold.

local dimensions is list(v(1, 0, 0), v(-1, 0, 0)).
local dimensions is list(v(1, 0, 0), v(-1, 0, 0)).
local position is v(x, 0, 0).
local minimum is cost(position).

Expand Down
12 changes: 8 additions & 4 deletions src/search.ks
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ local function find_launch_window {
local function iterated_local_search {
parameter verbose, earliest_departure, search_duration, max_time_of_flight, search_interval, step_threshold, total_deltav.

local x is earliest_departure.
local latest_departure is earliest_departure + search_duration.

// The default max_time_of_flight is twice the ideal Hohmann transfer time,
// so setting the intial guess to half of that will be reasonably close to
// the final value in most cases.
local y is max_time_of_flight * 0.5.
local latest_departure is earliest_departure + search_duration.
local step_size is search_interval * 0.1.

// Sneaky trick here. When comparing a scalar and a string, kOS converts the
Expand All @@ -142,10 +144,10 @@ local function iterated_local_search {
local result is lex("total_deltav", "max").
local invocations is 0.

from { local x is earliest_departure. } until x > latest_departure step { set x to x + search_interval. } do {
until x > latest_departure {
// Restrict x to a limited range of the total search space to save time.
// If x wanders too far from its original value, then most likely the
// prevous search has already found that minimum or the next search will
// previous search has already found that minimum or the next search will
// find it.
local min_x is max(earliest_departure, x - search_interval).
local max_x is min(latest_departure, x + 2 * search_interval).
Expand All @@ -157,7 +159,6 @@ local function iterated_local_search {
local flip_direction is retrograde_deltav < prograde_deltav.
local initial_deltav is choose retrograde_deltav if flip_direction else prograde_deltav.

set invocations to invocations + 2.
function cost {
parameter v.

Expand Down Expand Up @@ -192,6 +193,9 @@ local function iterated_local_search {
"flip_direction", flip_direction
).
}

set invocations to invocations + 2.
set x to x + search_interval.
}

if verbose {
Expand Down
2 changes: 1 addition & 1 deletion src/validate.ks
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ local function validate_orbital_constraints {
}

if not destination:hasbody {
problem(202, "Destination '" + destination:name + "' is not orbiting a parent body.").
problem(202, "Destination '" + destination:name + "' is not orbiting a parent body").
return.
}

Expand Down

0 comments on commit fa0c19a

Please sign in to comment.