SOURCE

console 命令行工具 X clear

                    
>
console
function generateGragh() {
  return {
    0: [1, 3, 4],
    1: [0, 2, 5],
    2: [1, 3, 6],
    3: [0, 2, 7],
    4: [0, 5, 7],
    5: [1, 4, 6],
    6: [2, 5, 7],
    7: [3, 4, 6]
  }
}

function getPathList(g, start, end) {
  const pointPathList = [], path = [start], stack = [[...g[start]]]
  while (path.length) {
    const nextPoints = stack[stack.length - 1]
    if (!nextPoints.length) {
      path.pop()
      stack.pop()
      continue
    }
    const nextPoint = nextPoints.shift()
    if (nextPoint == end) { // 该点已经是终点,则直接得到路径
      pointPathList.push([...path, nextPoint])
      continue
    }
    // 不是终点,则把它加入路径
    const newNextPoints = g[nextPoint].filter(p => !path.includes(p))
    path.push(nextPoint)
    stack.push(newNextPoints)
  }
  const edgePathList = []
  for (let path of pointPathList) {
    const pathEdge = []
    for (let idx = 0; idx < path.length - 1; idx++) {
      const edge = `${path[idx]}-${path[idx+1]}`
      pathEdge.push(edge)
    }
    edgePathList.push(pathEdge)
  }
  return edgePathList
}

function getEdgeList(g) {
  return Object.keys(g).reduce((r, start) => {
    g[start].forEach(end => start < end && r.push([+start, end]))
    return r
  }, [])
}

// 12条边的所有连通情况
function getAllSituations(nums) {
  const list = Array(nums).fill(undefined).map(() => ([true, false]))
  return list.reduce((result, subList) => {
    return subList.reduce((subResult, item) => {
      let tail = result.length ? result.map(l => [...l, item]) : [[item]]
      return subResult.concat(tail)
    }, [])
  }, [])
}

function getResult(a) {
  const g = generateGragh()
  const edgeList = getEdgeList(g) // 12条边
  const situations = getAllSituations(edgeList.length)
  const edgePathList = getPathList(g, 0, 6)
  return situations.reduce((r, s) => {
    let statusMap = {}, passNums = 0
    s.forEach((pass, idx) => {
      const [f, t] = edgeList[idx]
      statusMap[`${f}-${t}`] = statusMap[`${t}-${f}`] = pass
      pass && passNums++
    })
    if (edgePathList.find(path => path.every(edge => statusMap[edge]))) {
      r += (a ** passNums) * ((1 - a) ** (edgeList.length - passNums))
    }
    return r
  }, 0)
}
// console.log(getResult(.5))

function generateData () {
    const data = []
    for (let a = 0; a <= 1.1; a += .02) {
        data.push([a, getResult(a)])
    }
    return data
}

function drawGragh () {
    const el = document.querySelector('.gragh')
    if (el) {
        const chart = echarts.init(el)
        chart.setOption({
            animation: false,
            xAxis: {
                name: 'x',
                minorSplitLine: {
                    show: true,
                    lineStyle: {
                        color: '#ddd'
                    }
                }
            },
            yAxis: {
                name: 'y',
                min: -100,
                max: 100,
                minorSplitLine: {
                    show: true,
                    lineStyle: {
                        color: '#ddd'
                    }
                }
            },
            dataZoom: [{
                type: 'inside',
                filterMode: 'none',
                xAxisIndex: [0],
                startValue: 0,
                endValue: 1
            }, {
                type: 'inside',
                filterMode: 'none',
                yAxisIndex: [0],
                startValue: 0,
                endValue: 1
            }],
            series: [
                {
                    type: 'line',
                    showSymbol: false,
                    data: generateData()
                }
            ]
        })
    }
}

drawGragh()
<script crossorigin="anonymous" integrity="sha512-odXFR6jGqGLJay2LHI5hit0IEfyxJ2UexST/qvnljBPrbXMwU44CoVddZjD9EsrtS6bMOoz8lC2yU0nhyh9yyg==" src="https://lib.baomitu.com/echarts/5.0.0/echarts.common.js"></script>

<div class="gragh"></div>
.gragh {
    width: 600px;
    height: 600px;
}