FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Moon landing

A rocket is fired from the earth and must land on a particular location on the moon. The goal is to minimize the total consumed fuel.

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

Data Files


   Mosel NL examples
   file moonshot.mos
   Minimise fuel consumption of a rocket from earth to moon.
   Nonlinear objective and constraints

   Based on AMPL model moonshot.mod

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2013 Fair Issac Corporation
       author: S. Heipcke, Mar. 2013
model "moonshot"
  uses "mmxnlp"

    N = 100                        ! Number of discrete times
    D = 1..2                       ! Dimensions
    Nx: set of real                ! Discrete times for positions
    Nv: set of real                ! Discrete times for velocity
    Na: set of real                ! Discrete times for acceleration
    T: real                        ! Total time
    G: real                        ! Constant factor

    MASS_Earth: real               ! Mass of Earth
    RADIUS_Earth: real             ! Radius of Earth
    POS_Earth: array(D) of real    ! Position(x,y) of Earth
    MASS_Moon : real               ! Mass of Moon
    RADIUS_Moon : real             ! Radius of Moon
    POS_Moon : array(D) of real    ! Position(x,y) of Moon

    X0: array(D) of real           ! Initial position
    Xn: array(D) of real           ! Final position
    V0: array(D) of real           ! Initial velocity
    Vn: array(D) of real           ! Final velocity
    ALPHA0: real                   ! Initial degree
    ALPHAn: real                   ! Final degree

  Nx:= union(i in 0..N) {real(i)}
  Na:= union(i in 1..N-1) {real(i)}
  Nv:= union(i in 1..N) {i-0.5}

  initializations from "moonshot.dat"
    T  G  MASS_Earth MASS_Moon RADIUS_Earth RADIUS_Moon POS_Earth POS_Moon

! Initial and final velocity
  ALPHA0 := 1.5*M_PI
  ALPHAn := M_PI/2.0
  X0(1) := POS_Earth(1) + RADIUS_Earth*cos(ALPHA0)
  X0(2) := POS_Earth(2) + RADIUS_Earth*sin(ALPHA0)
  Xn(1) := POS_Moon(1) + RADIUS_Moon*cos(ALPHAn)
  Xn(2) := POS_Moon(2) + RADIUS_Moon*sin(ALPHAn)
  V0(1) := 5*cos(ALPHA0)
  V0(2) := 5*sin(ALPHA0)
  Vn(1) := -5*cos(ALPHAn)
  Vn(2) := -5*sin(ALPHAn)

    x: array(D, Nx) of mpvar        ! Position
    v: array(D, Nv) of mpvar        ! Velocity
    a: array(D, Na) of mpvar        ! Acceleration
    theta: array(D, Na) of mpvar    ! Thrust
    fuelcost: nlctr

! Objective function: total fuel consumption
  Fuelcost:= sum(d in D, i in Na) theta(d,i)^2

! Setting start values for positions
  forall(d in D, j in Nx) do
    setinitval(x(d,j), (1-j/N)*X0(d)+(j/N)*Xn(d) )
    x(d,j) is_free

! Fixing start and final position and velocity
  forall(d in D) do
    x(d, 0) = X0(d)                 ! Initial position
    x(d, N) = Xn(d)                 ! Final position
    v(d, 0.5) = V0(d)               ! Initial velocity
    v(d, N-0.5)^1 = Vn(d)           ! Final velocity

! Velocity constraint
  forall(d in D, j in Nv) do
    VelDef(d,j) := N*( x(d, j+0.5) - x(d, j-0.5) ) = T*v(d,j)
    v(d,j) is_free

! Acceleration constraint
  forall(d in D, j in Na) do
    AccDef(d,j) := N*( v(d, j+0.5) - v(d, j-0.5) ) = T*a(d,j)
    a(d,j) is_free
    theta(d,j) is_free 

! Force balance constraint
  forall(d in D, j in Na)
    Force(d,j) := a(d,j) =
        (sum(dd in D) (x(dd,j)-POS_Earth(dd))^2)^(3/2) -
        (sum(dd in D) (x(dd,j)-POS_Moon(dd))^2)^(3/2) +
! Setting up and solving the problem


! Solution printing
  forall(i in Na) 
    writeln("i=", i, ": position=(", x(1,i).sol, ",", x(2,i).sol, ")",
            " thrust=(",theta(1,i).sol, ",", theta(2,i).sol,"), ",
            "acceleration=(",getsol(a(1,i)), ",", getsol(a(2,i)),")" )
  forall(i in Nv) writeln("velocity=(",getsol(v(1,i)), ",",getsol(v(2,i)),")" )
  writeln("Fuelcost = ", getobjval, "\n")


Back to examples browserPrevious exampleNext example