Skip to content

Instantly share code, notes, and snippets.

@blvp
Created November 29, 2017 21:35
Show Gist options
  • Select an option

  • Save blvp/8ab0b6bcb5ce61cae6e43076bf71681e to your computer and use it in GitHub Desktop.

Select an option

Save blvp/8ab0b6bcb5ce61cae6e43076bf71681e to your computer and use it in GitHub Desktop.
$(document).ready ->
class TaskFour
MAX_VALUE = Number.MAX_VALUE
constructor: (n = 3) ->
@n = n
console.log "N = #{@n}"
@s = @_setArray(@n + 1)
@s[0] = 3.4
console.log "S1 = #{@s[0]}"
@s[@n] = 5.2
console.log "S{#{@n + 1}} = #{@s[@n]}"
@mumax_const = 3.2
console.log "mu max = #{@mumax_const}"
@ks_const = 5.3
console.log "ks = #{@ks_const}"
@y = 4.5
console.log "y = #{@y}"
@algorithm()
algorithm: ->
start = new Date().getTime()
theta = @_setArray()
interval = []
for i in [0..50] by 5
interval.push(i)
for i in [0...@n]
min_thetha_iter = MAX_VALUE
current_theta = theta[i]
current_s_next = @s[i + 1]
# выбираем возможный s_{i+1} выбираем минимальный
for s_next in interval
current_theta =
@theta(@s[i], s_next, @s[@n], i is @n - 1)
if current_theta < min_thetha_iter
current_s_next = s_next
min_thetha_iter = current_theta
# обновляем s_{i+1} и значения для i стейджа
@s[i + 1] = current_s_next
theta[i] = min_thetha_iter
for i in [0...theta.length]
resTheta = Math.round(theta[i])
console.log("theta {0} = #{i + 1} #{resTheta}")
end = new Date().getTime()
time = end - start
@res = [@n, time]
@res
theta: (s_current, s_next, s_last, is_last) ->
if is_last
val = (@ks_const + s_current) / @mumax_const / s_current
else
val = (@ks_const + s_current) * (s_next - s_current) / @mumax_const / s_current / (s_last - s_current)
if val > 0 then val else MAX_VALUE
_setArray: (step = 1) ->
array = []
for i in [0..@n] by step
array.push(0)
array.slice(0)
class App
constructor: ->
performanceArray = []
for i in [0...1000] by 10
alg = new TaskFour(i)
performanceArray.push(alg.res)
graphData = [
data: performanceArray
color: 'blue'
]
$.plot($('#graph-lines'), graphData, @getParams)
getParams: ->
params =
series:
points:
show: true
radius: 0
lines:
show: true
shadowSize: 2
grid:
color: "#646464"
borderColor: "transparent"
borderWidth: 20
hoverable: true
xaxis:
ticks: 15
tickColor: "transparent"
tickDecimals: 1
yaxis:
tickSize: 1
min: -1
max: 2
App()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment